Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Class cast exception
[Teneo] Class cast exception [message #424856] Fri, 07 November 2008 08:57 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

From this code (we changed it to an Object in the for loop to get a
better trace)


// open transaction
Session session = HibernateUtil.getCurrentSession();
Transaction tx = session.beginTransaction();

try
{
Query query = session.createQuery("from IssuerClass where id = ?");
query.setInteger(0, issuerId);

Object object = query.uniqueResult();
if (object instanceof IssuerClass) {

EList<Location> locations = ((IssuerClass)object).getLocation();
Location location = null ;
for (Object o : locations)
location = (Location) o ;
....

we get

Caused by: java.lang.ClassCastException:
org.eclipse.emf.teneo.hibernate.mapping.internal.TeneoIntern alEObject_$$_javassist_16
cannot be cast to com.stpenable.gensec.LocationType
at com.stpenable.gensec.impl.LocationImpl.eSet(LocationImpl.jav a:1085)
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjec tImpl.java:1071)
at
org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.set(EReferencePropertyHandler.java:150)
at
org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropert yValues(AbstractEntityTuplizer.java:360)
setLocationType((LocationType)newValue);
com.stpenable.gensec.impl.LocationTypeImpl@19e244f (full: domicile, id:
<unset>, scheme: mddl3b, short: domicile)
newValue TeneoInternalEObject_$$_javassist_16 (id=191)
handler JavassistLazyInitializer (id=195)

What have we done wrong?

Here is the xsd excerpt

<xsd:complexType name="IssuerClass">
<xsd:sequence>
<xsd:element ecore:opposite="issuerClass" minOccurs="0"
maxOccurs="unbounded" ref="gensec:location" />
..... etc.

Thx.

David
Re: [Teneo] Class cast exception [message #424858 is a reply to message #424856] Fri, 07 November 2008 10:28 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
It seems to be related to this:
http://www.hibernate.org/hib_docs/reference/en/html/performa nce.html#performance-fetching-proxies

Normally this should not be a problem.

What is the model of LocationType? It seems to go wrong when a LocationType is set in the Location.

gr. Martin

David Wynter wrote:
> Hi,
>
> From this code (we changed it to an Object in the for loop to get a
> better trace)
>
>
> // open transaction
> Session session = HibernateUtil.getCurrentSession();
> Transaction tx = session.beginTransaction();
>
> try
> {
> Query query = session.createQuery("from IssuerClass where id = ?");
> query.setInteger(0, issuerId);
>
> Object object = query.uniqueResult();
> if (object instanceof IssuerClass) {
>
> EList<Location> locations = ((IssuerClass)object).getLocation();
> Location location = null ;
> for (Object o : locations)
> location = (Location) o ;
> ....
>
> we get
>
> Caused by: java.lang.ClassCastException:
> org.eclipse.emf.teneo.hibernate.mapping.internal.TeneoIntern alEObject_$$_javassist_16
> cannot be cast to com.stpenable.gensec.LocationType
> at com.stpenable.gensec.impl.LocationImpl.eSet(LocationImpl.jav a:1085)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjec tImpl.java:1071)
>
> at
> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.set(EReferencePropertyHandler.java:150)
>
> at
> org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropert yValues(AbstractEntityTuplizer.java:360)
>
> setLocationType((LocationType)newValue);
> com.stpenable.gensec.impl.LocationTypeImpl@19e244f (full: domicile, id:
> <unset>, scheme: mddl3b, short: domicile)
> newValue TeneoInternalEObject_$$_javassist_16 (id=191)
> handler JavassistLazyInitializer (id=195)
>
> What have we done wrong?
>
> Here is the xsd excerpt
>
> <xsd:complexType name="IssuerClass">
> <xsd:sequence>
> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
> maxOccurs="unbounded" ref="gensec:location" />
> ..... etc.
>
> Thx.
>
> David


--

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: [Teneo] Class cast exception [message #424868 is a reply to message #424858] Fri, 07 November 2008 13:40 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Here is the fuller model.

<xsd:complexType name="Location">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element minOccurs="0" maxOccurs="1" ref="gensec:locationType" >
<xsd:annotation>
<xsd:appinfo
source="teneo.jpa">@JoinColumn(name="locationtype" insertable=false
updatable=false)</xsd:appinfo>
</xsd:annotation>
</xsd:element>
....

<xsd:complexType name="LocationType">
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="short" type="xsd:string" />
<xsd:attribute name="full" type="xsd:string" />
<xsd:attribute
default="http://www.mddl.org/mddl/scheme/locationType.xml" name="scheme"
use="optional" />
</xsd:complexType>
<xsd:element name="locationType" type="gensec:LocationType" />



With such a big model we used

props.setProperty(PersistenceOptions.SET_PROXY, "true");

to stop eager fetching. I will add it back where needed using the
@OneToMany(fetch=EAGER) later on.
It looks like I need to add an annotation for these 0..1 associations
like Location to LocationType right off the bat then?

David



Martin Taal wrote:
> Hi David,
> It seems to be related to this:
> http://www.hibernate.org/hib_docs/reference/en/html/performa nce.html#performance-fetching-proxies
>
>
> Normally this should not be a problem.
>
> What is the model of LocationType? It seems to go wrong when a
> LocationType is set in the Location.
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> From this code (we changed it to an Object in the for loop to get a
>> better trace)
>>
>>
>> // open transaction
>> Session session = HibernateUtil.getCurrentSession();
>> Transaction tx = session.beginTransaction();
>> try
>> {
>> Query query = session.createQuery("from IssuerClass where id = ?");
>> query.setInteger(0, issuerId);
>> Object object = query.uniqueResult();
>> if (object instanceof IssuerClass) {
>>
>> EList<Location> locations = ((IssuerClass)object).getLocation();
>> Location location = null ;
>> for (Object o : locations)
>> location = (Location) o ;
>> ....
>>
>> we get
>>
>> Caused by: java.lang.ClassCastException:
>> org.eclipse.emf.teneo.hibernate.mapping.internal.TeneoIntern alEObject_$$_javassist_16
>> cannot be cast to com.stpenable.gensec.LocationType
>> at com.stpenable.gensec.impl.LocationImpl.eSet(LocationImpl.jav a:1085)
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjec tImpl.java:1071)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.set(EReferencePropertyHandler.java:150)
>>
>> at
>> org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropert yValues(AbstractEntityTuplizer.java:360)
>>
>> setLocationType((LocationType)newValue);
>> com.stpenable.gensec.impl.LocationTypeImpl@19e244f (full: domicile,
>> id: <unset>, scheme: mddl3b, short: domicile)
>> newValue TeneoInternalEObject_$$_javassist_16 (id=191)
>> handler JavassistLazyInitializer (id=195)
>>
>> What have we done wrong?
>>
>> Here is the xsd excerpt
>>
>> <xsd:complexType name="IssuerClass">
>> <xsd:sequence>
>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>> maxOccurs="unbounded" ref="gensec:location" />
>> ..... etc.
>>
>> Thx.
>>
>> David
>
>
Re: [Teneo] Class cast exception [message #424871 is a reply to message #424858] Fri, 07 November 2008 15:23 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I cannot see the correlation between the performance fetching proxies
you show the link to and this problem, because we have no subclass here?
It is a straight IssuerClass 1..n Location 0..1 LocationType set of
relationships.

Based on this statement from the page you linked to "Note that the
proxied class must implement a default constructor with at least package
visibility. We recommend this constructor for all persistent classes! "
is there a reason no default constructor with the required visibility is
generated by Teneo?

Thx.

David

Martin Taal wrote:
> Hi David,
> It seems to be related to this:
> http://www.hibernate.org/hib_docs/reference/en/html/performa nce.html#performance-fetching-proxies
>
>
> Normally this should not be a problem.
>
> What is the model of LocationType? It seems to go wrong when a
> LocationType is set in the Location.
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> From this code (we changed it to an Object in the for loop to get a
>> better trace)
>>
>>
>> // open transaction
>> Session session = HibernateUtil.getCurrentSession();
>> Transaction tx = session.beginTransaction();
>> try
>> {
>> Query query = session.createQuery("from IssuerClass where id = ?");
>> query.setInteger(0, issuerId);
>> Object object = query.uniqueResult();
>> if (object instanceof IssuerClass) {
>>
>> EList<Location> locations = ((IssuerClass)object).getLocation();
>> Location location = null ;
>> for (Object o : locations)
>> location = (Location) o ;
>> ....
>>
>> we get
>>
>> Caused by: java.lang.ClassCastException:
>> org.eclipse.emf.teneo.hibernate.mapping.internal.TeneoIntern alEObject_$$_javassist_16
>> cannot be cast to com.stpenable.gensec.LocationType
>> at com.stpenable.gensec.impl.LocationImpl.eSet(LocationImpl.jav a:1085)
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjec tImpl.java:1071)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.set(EReferencePropertyHandler.java:150)
>>
>> at
>> org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropert yValues(AbstractEntityTuplizer.java:360)
>>
>> setLocationType((LocationType)newValue);
>> com.stpenable.gensec.impl.LocationTypeImpl@19e244f (full: domicile,
>> id: <unset>, scheme: mddl3b, short: domicile)
>> newValue TeneoInternalEObject_$$_javassist_16 (id=191)
>> handler JavassistLazyInitializer (id=195)
>>
>> What have we done wrong?
>>
>> Here is the xsd excerpt
>>
>> <xsd:complexType name="IssuerClass">
>> <xsd:sequence>
>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>> maxOccurs="unbounded" ref="gensec:location" />
>> ..... etc.
>>
>> Thx.
>>
>> David
>
>
Re: [Teneo] Class cast exception [message #424872 is a reply to message #424871] Fri, 07 November 2008 15:27 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Yes it is possible that it does not apply to your case (I did not know the whole model when reacting
to your post).
No constructor is the same as a public constructor without parameters.

I tested this model and the LocationType with me is of this type:
locationType LocationType$$EnhancerByCGLIB$$e0f520b9 (id=49)

this is correct, so it is cglib enhanced but still has the main type (LocationType).

So maybe you generated your code in a different way than I did?
Or can you send me the whole model with genmodel and testcase?

gr. Martin

David Wynter wrote:
> Hi,
>
> I cannot see the correlation between the performance fetching proxies
> you show the link to and this problem, because we have no subclass here?
> It is a straight IssuerClass 1..n Location 0..1 LocationType set of
> relationships.
>
> Based on this statement from the page you linked to "Note that the
> proxied class must implement a default constructor with at least package
> visibility. We recommend this constructor for all persistent classes! "
> is there a reason no default constructor with the required visibility is
> generated by Teneo?
>
> Thx.
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> It seems to be related to this:
>> http://www.hibernate.org/hib_docs/reference/en/html/performa nce.html#performance-fetching-proxies
>>
>>
>> Normally this should not be a problem.
>>
>> What is the model of LocationType? It seems to go wrong when a
>> LocationType is set in the Location.
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> From this code (we changed it to an Object in the for loop to get a
>>> better trace)
>>>
>>>
>>> // open transaction
>>> Session session = HibernateUtil.getCurrentSession();
>>> Transaction tx = session.beginTransaction();
>>> try
>>> {
>>> Query query = session.createQuery("from IssuerClass where id = ?");
>>> query.setInteger(0, issuerId);
>>> Object object = query.uniqueResult();
>>> if (object instanceof IssuerClass) {
>>>
>>> EList<Location> locations = ((IssuerClass)object).getLocation();
>>> Location location = null ;
>>> for (Object o : locations)
>>> location = (Location) o ;
>>> ....
>>>
>>> we get
>>>
>>> Caused by: java.lang.ClassCastException:
>>> org.eclipse.emf.teneo.hibernate.mapping.internal.TeneoIntern alEObject_$$_javassist_16
>>> cannot be cast to com.stpenable.gensec.LocationType
>>> at com.stpenable.gensec.impl.LocationImpl.eSet(LocationImpl.jav a:1085)
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjec tImpl.java:1071)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.set(EReferencePropertyHandler.java:150)
>>>
>>> at
>>> org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropert yValues(AbstractEntityTuplizer.java:360)
>>>
>>> setLocationType((LocationType)newValue);
>>> com.stpenable.gensec.impl.LocationTypeImpl@19e244f (full: domicile,
>>> id: <unset>, scheme: mddl3b, short: domicile)
>>> newValue TeneoInternalEObject_$$_javassist_16 (id=191)
>>> handler JavassistLazyInitializer (id=195)
>>>
>>> What have we done wrong?
>>>
>>> Here is the xsd excerpt
>>>
>>> <xsd:complexType name="IssuerClass">
>>> <xsd:sequence>
>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>> maxOccurs="unbounded" ref="gensec:location" />
>>> ..... etc.
>>>
>>> Thx.
>>>
>>> David
>>
>>


--

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:cdo packages
Next Topic:How to implement nodes with variable number of properties
Goto Forum:
  


Current Time: Sat Apr 27 04:03:10 GMT 2024

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

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

Back to the top