-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to map part of composite id as one-to-many set
PostPosted: Sun Sep 11, 2005 7:03 pm 
Newbie

Joined: Sun Sep 11, 2005 6:28 pm
Posts: 2
Hi, I got a problem of mapping following relationships,
Say: I have following three tables :

Table_A:
a_id (PK),
a_version (PK)
a_name

Table_B:
a_id (FK)
a_version(FK)
b_name,
..

Table_C
c_id, (PK)
c_version, (PK)
c_name,
a_id, (FK)
other_field,
...


I tried to map aid and a_version of Table_A to composite id, it worked fine with one-to-many association with Table_B. But I didn't work out mapping the association between table_A and Table_C as Table_C only has one foreign key aid.
I did try to use only aid as id in Table_A mapping file, and mapped a_verison as <verison>, but seemed not easy to map association between Table_A and Table_B.

Now I want to go for the composite id solution, any idea about how to map Table_A to Table_C? The following is the mapping file that doesn't work, I got "exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info)"






Hibernate version:3.0

Mapping documents:


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<class name="ClassA" table="Table_A">

<composite-id
name="aPK"
class="test.PK"
unsaved-value="none"
>
<key-property name="aid"
type="string"
column="a_id" />
<key-property name="aVersion"
type="long"
column="a_version" />
</composite-id>

<set name="bSet"
inverse="true"
lazy="true"
cascade="save-update">
<key>
<column name="a_id" />
<column name="a_version" />
</key>
<one-to-many class="ClassB" />
</set>

<set name="cSet"
inverse="true"
lazy="true"
cascade="save-update">
<key property-ref="aid">
<column name="a_id" />
</key>

<one-to-many class="ClassC" />

</set>

</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

org.hibernate.PropertyAccessException: exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of APK.?
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:42)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:257)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:158)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:68)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:41)
at org.hibernate.engine.PersistenceContext.getCollectionOwner(PersistenceContext.java:674)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:660)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:370)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:314)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:176)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:110)
...
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassCastException
at APK$$BulkBeanByCGLIB$$8f063a72_2.getPropertyValues(<generated>)
at net.sf.cglib.beans.BulkBean.getPropertyValues(BulkBean.java:48)
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:39)
... 52 more



Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.