-->
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.  [ 2 posts ] 
Author Message
 Post subject: polymorphic collection problem
PostPosted: Fri Jun 17, 2005 3:04 pm 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
Hibernate version: 3.05

Mapping extracts:

<class name="com.itth.sto.om.Shopable" table="Shopable">
[..]
<joined-subclass name="com.itth.sto.om.Book" table="Book">
<key column="id"/>
[..]


<class name="com.itth.sto.om.CartsShopable" table="CartsShopable">
[..]
<many-to-one name="shopable" class="com.itth.sto.om.Shopable"
cascade="none" outer-join="auto" update="true" insert="true">
<column name="shopableId"/>
</many-to-one>
[..]

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

Code:
           
Shopable shopable = (Shopable) session.get(Shopable.class, bookId);
Cart cart = (Cart) session.get(Cart.class, cartId);

cartsShopable = new CartsShopable();
cartsShopable.setShopable(shopable);
cartsShopable.setCart(cart);
cartsShopable.setPrice(shopable.getPrice());
cartsShopable.save();



Full stack trace of any exception that occurs:
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.itth.sto.om.Book
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:99)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:63)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1963)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)

Name and version of the database you are using:
MySQL 4.1.9

I have the problem that Hibernate thinks my objects which inherit Shopable are unsaved. I use the table-per-subclass schema with joined-subclass. In chapter 10.1.4. of the docu it is said: For any of these mapping strategies, a polymorphic association to the root Payment class is mapped using <many-to-one>.
But sometimes when I want to add a (polymorphic) Shopable Hibernate throws the exception above.

Thanks for your suggestions
Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 3:00 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
For my shame I omitted a version field which was not initialized in the right way. I found this via debugging (stepping through hibernate) until I found which was the cause. Perhaps the cause could be told in the exception thrown.

Sorry for noise
Thomas


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

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.