Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Classcast exception when Second Level Caching enabled
Classcast exception when Second Level Caching enabled [message #124341] Fri, 30 May 2008 23:16 Go to next message
Eclipse UserFriend
Originally posted by: sprakash.tibco.com

Hello Martin,
Is second-level caching not supported by Teneo, or am I doing something
wrong? I'm using Teneo 0.7.5, and when I add the property
teneo.mapping.default_cache_strategy=READ_WRITE, my otherwise correctly
working program (doing a very simple query) immediately gets a
ClassCastException. What am I doing wrong?

Thanks in advance,

Sundeep

Relevant Log:

69718 [main] DEBUG
org.eclipse.emf.teneo.hibernate.mapping.property.EListProper tyHandler -
Set value org.hibernate.collection.PersistentList for target
com.tibco.matrix.models.administrationmodel.impl.AdminCluste rImpl field
serviceConfigurations
69734 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - adding entity to
second-level cache: [AdminCluster#1]
...
Caused by: java.lang.ClassCastException:
com.tibco.matrix.models.administrationmodel.impl.EnterpriseI mpl
at org.hibernate.type.AbstractType.disassemble(AbstractType.jav a:54)
at org.hibernate.type.TypeFactory.disassemble(TypeFactory.java: 451)
at org.hibernate.cache.entry.CacheEntry.<init>(CacheEntry.java:46)
at
org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseL oad.java:141)
at
org.hibernate.loader.Loader.initializeEntitiesAndCollections (Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyColle ctions(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
at
org.hibernate.loader.entity.AbstractEntityLoader.load(Abstra ctEntityLoader.java:48)
at
org.hibernate.loader.entity.AbstractEntityLoader.load(Abstra ctEntityLoader.java:42)
at
org.hibernate.persister.entity.AbstractEntityPersister.load( AbstractEntityPersister.java:3044)
at
org.hibernate.event.def.DefaultLoadEventListener.loadFromDat asource(DefaultLoadEventListener.java:395)
at
org.hibernate.event.def.DefaultLoadEventListener.doLoad(Defa ultLoadEventListener.java:375)
at
org.hibernate.event.def.DefaultLoadEventListener.load(Defaul tLoadEventListener.java:139)
at
org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad (DefaultLoadEventListener.java:179)
at
org.hibernate.event.def.DefaultLoadEventListener.onLoad(Defa ultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878 )
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java :846)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.j ava:557)
at org.hibernate.type.EntityType.resolve(EntityType.java:379)
at
org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseL oad.java:116)
at
org.hibernate.loader.Loader.initializeEntitiesAndCollections (Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyColle ctions(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java :2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:3 78)
at
org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslat orImpl.java:338)
at
org.hibernate.engine.query.HQLQueryPlan.performList(HQLQuery Plan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
(Please help) Re: Classcast exception when Second Level Caching enabled [message #124439 is a reply to message #124341] Sat, 31 May 2008 20:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sprakash.tibco.com

I'm totally stumped, please help!

I found that when Hibernate is attempting to disassemble the object (in
order to put it in the second level cache), it basically expects to get a
Serializable value for each of the non-collection, non-reference
attributes of the object. One such attribute is eContainer, part of the
basic EMF model itself. Now, the eContainer of my object is another EMF
model object (object#2) I have. In order to get a Serializable value for
this object#2 it calls
org.eclipse.emf.teneo.hibernate.mapping.econtainer.EContaine rUserType.deepCopy(Object
value, EntityMode entityMode, SessionFactoryImplementor factory) on
object#2. This method simply returns the object#2 itself, which is not
Serializable, hence the ClassCast exception.

So what does this mean? That all of my objects that contain other objects
must be Serializable? It simply doesnt make sense.. The deep copy itself
shouldnt be done, it should simply store a reference to the object..Please
help..

Thanks

Sundeep
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #124452 is a reply to message #124439] Sat, 31 May 2008 20:37 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sundeep,
I saw your post. I am first working on another post (the one with title: Re: [CDO] reading/writting
throughput performances). It is a bit more efficient for me to first finish one and then look at the
other. Especially on a saturday evening...

gr. Martin

Sundeep Prakash wrote:
> I'm totally stumped, please help!
>
> I found that when Hibernate is attempting to disassemble the object (in
> order to put it in the second level cache), it basically expects to get
> a Serializable value for each of the non-collection, non-reference
> attributes of the object. One such attribute is eContainer, part of the
> basic EMF model itself. Now, the eContainer of my object is another EMF
> model object (object#2) I have. In order to get a Serializable value for
> this object#2 it calls
> org.eclipse.emf.teneo.hibernate.mapping.econtainer.EContaine rUserType.deepCopy(Object
> value, EntityMode entityMode, SessionFactoryImplementor factory) on
> object#2. This method simply returns the object#2 itself, which is not
> Serializable, hence the ClassCast exception.
> So what does this mean? That all of my objects that contain other
> objects must be Serializable? It simply doesnt make sense.. The deep
> copy itself shouldnt be done, it should simply store a reference to the
> object..Please help..
>
> Thanks
>
> Sundeep
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #124465 is a reply to message #124439] Sat, 31 May 2008 22:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sundeep,
Hmmm, I think that there are two options to handle this:
- the EContainerUserType.deepcopy should return null always (instead of the passed value);
- the EContainerUserType.deepcopy should return an id-like object. See the disassemble method in the
EContainerUserType. It returns a ContainerPointer.

To change this you have to override the EContainerUserType and override the deepcopy method. Then to
override the addContainerMapping method in the datastore. You should copy most of the method and
only change this call:
sv.setTypeName(EContainerUserType.class.getName());
to pass your own custom EContainerUserType.

I hope this helps.

btw, I am not actively maintaining the 0.7.5 branch. So the above description is based on
0.8.0/1.0.0. But afair this part has not changed that much.

gr. Martin

Sundeep Prakash wrote:
> I'm totally stumped, please help!
>
> I found that when Hibernate is attempting to disassemble the object (in
> order to put it in the second level cache), it basically expects to get
> a Serializable value for each of the non-collection, non-reference
> attributes of the object. One such attribute is eContainer, part of the
> basic EMF model itself. Now, the eContainer of my object is another EMF
> model object (object#2) I have. In order to get a Serializable value for
> this object#2 it calls
> org.eclipse.emf.teneo.hibernate.mapping.econtainer.EContaine rUserType.deepCopy(Object
> value, EntityMode entityMode, SessionFactoryImplementor factory) on
> object#2. This method simply returns the object#2 itself, which is not
> Serializable, hence the ClassCast exception.
> So what does this mean? That all of my objects that contain other
> objects must be Serializable? It simply doesnt make sense.. The deep
> copy itself shouldnt be done, it should simply store a reference to the
> object..Please help..
>
> Thanks
>
> Sundeep
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #125143 is a reply to message #124465] Wed, 04 June 2008 18:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sprakash.tibco.com

Martin,
Thank you for your response! I was a bit worried that this might turn out
to be like the Hibernate forums :-) It's virtually impossible to get a
response there..

I will try out what you suggest, but in general, this seems to mean that
second level caching does not currently work with Teneo 0.7.5/0.8.x? Do I
understand correctly? Because it's not just my models that have an
eContainer, all EMF models do and unless the eContainers are serializable
they would invariably hit up against this ClassCastException. Am I missing
something?

Thanks very much,

Sundeep
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #125144 is a reply to message #125143] Wed, 04 June 2008 19:59 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sundeep,
Afaics you are right. I have a testcase for second level cache but this testcase has serializable
modelclasses so this works fine...

Also the customer cases where I used emf/hibernate I have always made the model classes serializable.

I am starting to wonder if others encountered this issue...

Btw, you can also disable the econtainer mapping by setting the property
PersistenceOptions.DISABLE_ECONTAINER_MAPPING to true.

I will solve this in the next build.

gr. Martin

Sundeep Prakash wrote:
> Martin,
> Thank you for your response! I was a bit worried that this might turn
> out to be like the Hibernate forums :-) It's virtually impossible to get
> a response there..
>
> I will try out what you suggest, but in general, this seems to mean that
> second level caching does not currently work with Teneo 0.7.5/0.8.x? Do
> I understand correctly? Because it's not just my models that have an
> eContainer, all EMF models do and unless the eContainers are
> serializable they would invariably hit up against this
> ClassCastException. Am I missing something?
>
> Thanks very much,
>
> Sundeep


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #125146 is a reply to message #125144] Wed, 04 June 2008 20:29 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Fix for this has been committed to cvs. The bugzilla is:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=235696

gr. Martin

Martin Taal wrote:
> Hi Sundeep,
> Afaics you are right. I have a testcase for second level cache but this
> testcase has serializable modelclasses so this works fine...
>
> Also the customer cases where I used emf/hibernate I have always made
> the model classes serializable.
>
> I am starting to wonder if others encountered this issue...
>
> Btw, you can also disable the econtainer mapping by setting the property
> PersistenceOptions.DISABLE_ECONTAINER_MAPPING to true.
>
> I will solve this in the next build.
>
> gr. Martin
>
> Sundeep Prakash wrote:
>> Martin,
>> Thank you for your response! I was a bit worried that this might turn
>> out to be like the Hibernate forums :-) It's virtually impossible to
>> get a response there..
>>
>> I will try out what you suggest, but in general, this seems to mean
>> that second level caching does not currently work with Teneo
>> 0.7.5/0.8.x? Do I understand correctly? Because it's not just my
>> models that have an eContainer, all EMF models do and unless the
>> eContainers are serializable they would invariably hit up against this
>> ClassCastException. Am I missing something?
>>
>> Thanks very much,
>>
>> Sundeep
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
(Please help) Re: Classcast exception when Second Level Caching enabled [message #619123 is a reply to message #124341] Sat, 31 May 2008 20:28 Go to previous message
Sundeep Prakash is currently offline Sundeep PrakashFriend
Messages: 14
Registered: July 2009
Junior Member
I'm totally stumped, please help!

I found that when Hibernate is attempting to disassemble the object (in
order to put it in the second level cache), it basically expects to get a
Serializable value for each of the non-collection, non-reference
attributes of the object. One such attribute is eContainer, part of the
basic EMF model itself. Now, the eContainer of my object is another EMF
model object (object#2) I have. In order to get a Serializable value for
this object#2 it calls
org.eclipse.emf.teneo.hibernate.mapping.econtainer.EContaine rUserType.deepCopy(Object
value, EntityMode entityMode, SessionFactoryImplementor factory) on
object#2. This method simply returns the object#2 itself, which is not
Serializable, hence the ClassCast exception.

So what does this mean? That all of my objects that contain other objects
must be Serializable? It simply doesnt make sense.. The deep copy itself
shouldnt be done, it should simply store a reference to the object..Please
help..

Thanks

Sundeep
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #619124 is a reply to message #124439] Sat, 31 May 2008 20:37 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sundeep,
I saw your post. I am first working on another post (the one with title: Re: [CDO] reading/writting
throughput performances). It is a bit more efficient for me to first finish one and then look at the
other. Especially on a saturday evening...

gr. Martin

Sundeep Prakash wrote:
> I'm totally stumped, please help!
>
> I found that when Hibernate is attempting to disassemble the object (in
> order to put it in the second level cache), it basically expects to get
> a Serializable value for each of the non-collection, non-reference
> attributes of the object. One such attribute is eContainer, part of the
> basic EMF model itself. Now, the eContainer of my object is another EMF
> model object (object#2) I have. In order to get a Serializable value for
> this object#2 it calls
> org.eclipse.emf.teneo.hibernate.mapping.econtainer.EContaine rUserType.deepCopy(Object
> value, EntityMode entityMode, SessionFactoryImplementor factory) on
> object#2. This method simply returns the object#2 itself, which is not
> Serializable, hence the ClassCast exception.
> So what does this mean? That all of my objects that contain other
> objects must be Serializable? It simply doesnt make sense.. The deep
> copy itself shouldnt be done, it should simply store a reference to the
> object..Please help..
>
> Thanks
>
> Sundeep
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #619125 is a reply to message #124439] Sat, 31 May 2008 22:31 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sundeep,
Hmmm, I think that there are two options to handle this:
- the EContainerUserType.deepcopy should return null always (instead of the passed value);
- the EContainerUserType.deepcopy should return an id-like object. See the disassemble method in the
EContainerUserType. It returns a ContainerPointer.

To change this you have to override the EContainerUserType and override the deepcopy method. Then to
override the addContainerMapping method in the datastore. You should copy most of the method and
only change this call:
sv.setTypeName(EContainerUserType.class.getName());
to pass your own custom EContainerUserType.

I hope this helps.

btw, I am not actively maintaining the 0.7.5 branch. So the above description is based on
0.8.0/1.0.0. But afair this part has not changed that much.

gr. Martin

Sundeep Prakash wrote:
> I'm totally stumped, please help!
>
> I found that when Hibernate is attempting to disassemble the object (in
> order to put it in the second level cache), it basically expects to get
> a Serializable value for each of the non-collection, non-reference
> attributes of the object. One such attribute is eContainer, part of the
> basic EMF model itself. Now, the eContainer of my object is another EMF
> model object (object#2) I have. In order to get a Serializable value for
> this object#2 it calls
> org.eclipse.emf.teneo.hibernate.mapping.econtainer.EContaine rUserType.deepCopy(Object
> value, EntityMode entityMode, SessionFactoryImplementor factory) on
> object#2. This method simply returns the object#2 itself, which is not
> Serializable, hence the ClassCast exception.
> So what does this mean? That all of my objects that contain other
> objects must be Serializable? It simply doesnt make sense.. The deep
> copy itself shouldnt be done, it should simply store a reference to the
> object..Please help..
>
> Thanks
>
> Sundeep
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #619172 is a reply to message #124465] Wed, 04 June 2008 18:48 Go to previous message
Sundeep Prakash is currently offline Sundeep PrakashFriend
Messages: 14
Registered: July 2009
Junior Member
Martin,
Thank you for your response! I was a bit worried that this might turn out
to be like the Hibernate forums :-) It's virtually impossible to get a
response there..

I will try out what you suggest, but in general, this seems to mean that
second level caching does not currently work with Teneo 0.7.5/0.8.x? Do I
understand correctly? Because it's not just my models that have an
eContainer, all EMF models do and unless the eContainers are serializable
they would invariably hit up against this ClassCastException. Am I missing
something?

Thanks very much,

Sundeep
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #619173 is a reply to message #125143] Wed, 04 June 2008 19:59 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Sundeep,
Afaics you are right. I have a testcase for second level cache but this testcase has serializable
modelclasses so this works fine...

Also the customer cases where I used emf/hibernate I have always made the model classes serializable.

I am starting to wonder if others encountered this issue...

Btw, you can also disable the econtainer mapping by setting the property
PersistenceOptions.DISABLE_ECONTAINER_MAPPING to true.

I will solve this in the next build.

gr. Martin

Sundeep Prakash wrote:
> Martin,
> Thank you for your response! I was a bit worried that this might turn
> out to be like the Hibernate forums :-) It's virtually impossible to get
> a response there..
>
> I will try out what you suggest, but in general, this seems to mean that
> second level caching does not currently work with Teneo 0.7.5/0.8.x? Do
> I understand correctly? Because it's not just my models that have an
> eContainer, all EMF models do and unless the eContainers are
> serializable they would invariably hit up against this
> ClassCastException. Am I missing something?
>
> Thanks very much,
>
> Sundeep


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: (Please help) Re: Classcast exception when Second Level Caching enabled [message #619174 is a reply to message #125144] Wed, 04 June 2008 20:29 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Fix for this has been committed to cvs. The bugzilla is:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=235696

gr. Martin

Martin Taal wrote:
> Hi Sundeep,
> Afaics you are right. I have a testcase for second level cache but this
> testcase has serializable modelclasses so this works fine...
>
> Also the customer cases where I used emf/hibernate I have always made
> the model classes serializable.
>
> I am starting to wonder if others encountered this issue...
>
> Btw, you can also disable the econtainer mapping by setting the property
> PersistenceOptions.DISABLE_ECONTAINER_MAPPING to true.
>
> I will solve this in the next build.
>
> gr. Martin
>
> Sundeep Prakash wrote:
>> Martin,
>> Thank you for your response! I was a bit worried that this might turn
>> out to be like the Hibernate forums :-) It's virtually impossible to
>> get a response there..
>>
>> I will try out what you suggest, but in general, this seems to mean
>> that second level caching does not currently work with Teneo
>> 0.7.5/0.8.x? Do I understand correctly? Because it's not just my
>> models that have an eContainer, all EMF models do and unless the
>> eContainers are serializable they would invariably hit up against this
>> ClassCastException. Am I missing something?
>>
>> Thanks very much,
>>
>> Sundeep
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:[Teneo] Switch to DB2 and not getting identity columns
Next Topic:EMF Compare & ChangeDescription on Teneo/Database backed EMF objects
Goto Forum:
  


Current Time: Tue Apr 16 20:13:35 GMT 2024

Powered by FUDForum. Page generated in 1.76416 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top