Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo][Hibernate] ClassCastException: HibernatePersistableEList cannot be cast to BasicEList
[Teneo][Hibernate] ClassCastException: HibernatePersistableEList cannot be cast to BasicEList [message #875388] Tue, 22 May 2012 16:43 Go to next message
Markus Gulden is currently offline Markus GuldenFriend
Messages: 5
Registered: May 2012
Junior Member
Hi there,

I have a simple EMF model, consisting of two types, Type1 and Type2. Type1 has a 1-*-reference called list on Type2.

In the generated code, normally, I would get a getter like

public EList getList() {
		if (list == null) {
			list = new EObjectResolvingEList(Type2.class, this, Root_packagePackage.TYPE1__LIST);
		}
		return list;
	}


Since I need a non-generic field for an XTend based code generator, I changed the Array Accessors property in my GenModel to "true", and now I have a getter like

public Type2[] getList() {
		if (list == null || list.isEmpty()) return LIST_EEMPTY_ARRAY;
		BasicEList list = (BasicEList)list;
		list.shrink();
		return (Type2[])list.data();
	}


For my generator, this works fine, but when I query a persisted object of Type1 via Teneo and Hibernate and access the Type2 field, in line

BasicEList list = (BasicEList)list;

I get the exception

java.lang.ClassCastException: org.eclipse.emf.teneo.hibernate.mapping.elist.HibernatePersistableEList cannot be cast to org.eclipse.emf.common.util.BasicEList


If I would change the BasicEList manually to EList, it works, but I think, this is not a real option.

Does anybody have an idea to solve this problem of incompatible types?

[Updated on: Tue, 22 May 2012 17:15]

Report message to a moderator

Re: [Teneo][Hibernate] [message #875420 is a reply to message #875388] Tue, 22 May 2012 18:11 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
He Markus,
Why is it not an option to cast to EList?
It is not so easy to change this the persistableelist inherits from the DelegatingEcoreElist not from BasicElist.

gr. Martin

On 05/22/2012 06:43 PM, Markus Gulden wrote:
> Hi there,
>
> I have a simple EMF model, consisting of two types, Type1 and Type2. Type1 has a 1-*-reference called list on Type2.
>
> In the generated code, normally, I would get a getter like
>
> public EList getList() {
> if (list == null) {
> list = new EObjectResolvingEList(Type2.class, this, Root_packagePackage.TYPE1__LIST);
> }
> return list;
> }
>
> Since I need a non-generic field for an XTend based code generator, I changed the Array Accessors property in my
> GenModel to "true", and now I have a getter like
>
> public Type2[] getList() {
> if (list == null || list.isEmpty()) return LIST_EEMPTY_ARRAY;
> BasicEList list = (BasicEList)list;
> list.shrink();
> return (Type2[])list.data();
> }
>
> For my generator, this works fine, but when I query a persisted object of Type1 via Teneo and Hibernate and access the
> Type2 field, in line
>
> BasicEList list = (BasicEList)list;
> I get the exception
>
> java.lang.ClassCastException: org.eclipse.emf.teneo.hibernate.mapping.elist.HibernatePersistableEList cannot be cast to
> org.eclipse.emf.common.util.BasicEList
>
> If I change the BasicEList manually to EList, it works, but I think, this is not a real option.
>
> Does anybody have an idea to solve this problem?


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo][Hibernate] [message #875690 is a reply to message #875420] Wed, 23 May 2012 07:34 Go to previous messageGo to next message
Markus Gulden is currently offline Markus GuldenFriend
Messages: 5
Registered: May 2012
Junior Member
Hi Martin,

thanks for your reply.

Doesn't MDD with code generation aim to make manual coding needless, at least at such basic features like getters?

The getters are generated by EMF, forgot to mention that, but I thought that would be clear.

I don't know, what of both is the problem, that EMF doesn't use the root type EList, or that the Teneo list doesn't inheritate the BasicEList?
Re: [Teneo][Hibernate] [message #875709 is a reply to message #875690] Wed, 23 May 2012 07:59 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Because EList doesn't have the shrink() method which is called so that
data() returns the correct result.

I guess the reason not to use List.toArray() is performance. The code
trys to avoid the copying - what worries me about the generated method
is that data returns the internal data structure so one could modify a
BasicEList without any event getting triggered but maybe that's
intentional behavior?

Maybe the code generator could be changed to something like this:

public Type2[] getList() {
if (list == null || list.isEmpty()) return LIST_EEMPTY_ARRAY;
if( list instanceof BasicEList) {
BasicEList list = (BasicEList)list;
list.shrink();
return (Type2[])list.data();
} else {
return list.toArray(new Type2[0]);
}
}

This would still give you some overhead because of the instance of check
and the potential that once you get the internal datastructure you can
modify (if it is an BasicEList) and a copy of its not an BasicEList.

I'm still not sure why you need to have Type2[] because when generating
Java5 sourcecode you'd get the correct type signature EList<Type2>.

Tom

Am 23.05.12 09:34, schrieb Markus Gulden:
> Hi Martin,
>
> thanks for your reply.
>
> Doesn't MDD with code generation aim to make manual coding needless, at
> least at such basic features like getters?
>
> The getters are generated by EMF, forgot to mention that, but I thought
> that would be clear.
>
> I don't know, what of both is the problem, that EMF doesn't use the root
> type EList, or that the Teneo list doesn't inheritate the BasicEList?
Re: [Teneo][Hibernate] [message #875746 is a reply to message #875709] Wed, 23 May 2012 09:08 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Markus,
Ha sorry you are right this is EMF generated code... The reality is that I have not encountered anyone using this array
feature with Teneo, so it was never taken into account... It will be quite difficult to support this, as Teneo's EList
use the DelegatingEcoreList. So I am afraid that you can't use this Teneo in this scenario.

gr. Martin

On 05/23/2012 09:59 AM, Tom Schindl wrote:
> Because EList doesn't have the shrink() method which is called so that
> data() returns the correct result.
>
> I guess the reason not to use List.toArray() is performance. The code
> trys to avoid the copying - what worries me about the generated method
> is that data returns the internal data structure so one could modify a
> BasicEList without any event getting triggered but maybe that's
> intentional behavior?
>
> Maybe the code generator could be changed to something like this:
>
> public Type2[] getList() {
> if (list == null || list.isEmpty()) return LIST_EEMPTY_ARRAY;
> if( list instanceof BasicEList) {
> BasicEList list = (BasicEList)list;
> list.shrink();
> return (Type2[])list.data();
> } else {
> return list.toArray(new Type2[0]);
> }
> }
>
> This would still give you some overhead because of the instance of check
> and the potential that once you get the internal datastructure you can
> modify (if it is an BasicEList) and a copy of its not an BasicEList.
>
> I'm still not sure why you need to have Type2[] because when generating
> Java5 sourcecode you'd get the correct type signature EList<Type2>.
>
> Tom
>
> Am 23.05.12 09:34, schrieb Markus Gulden:
>> Hi Martin,
>>
>> thanks for your reply.
>>
>> Doesn't MDD with code generation aim to make manual coding needless, at
>> least at such basic features like getters?
>>
>> The getters are generated by EMF, forgot to mention that, but I thought
>> that would be clear.
>>
>> I don't know, what of both is the problem, that EMF doesn't use the root
>> type EList, or that the Teneo list doesn't inheritate the BasicEList?
>


--

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@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Teneo][Hibernate] [message #875747 is a reply to message #875709] Wed, 23 May 2012 09:13 Go to previous message
Markus Gulden is currently offline Markus GuldenFriend
Messages: 5
Registered: May 2012
Junior Member
Quote:

I'm still not sure why you need to have Type2[] because when generating
Java5 sourcecode you'd get the correct type signature EList<Type2>.


This was the solution:
The compliance level of my GenModel was on 1.4, I changed it to 6.0, now I get the wanted EList<Type2> getter.

Thanks a lot!
Previous Topic:[Validation] How to capture "Validate" Event in the Editor
Next Topic:Serialization of EList
Goto Forum:
  


Current Time: Wed Apr 24 18:29:30 GMT 2024

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

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

Back to the top