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