aspose file tools*
The moose likes Object Relational Mapping and the fly likes Could not synchronize database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Could not synchronize database" Watch "Could not synchronize database" New topic
Author

Could not synchronize database

durga prasadk
Greenhorn

Joined: Aug 02, 2008
Posts: 5
Hi ,

im new to ORM, im trying to use many-to-one assosiation , im getting exception like
----------------------------------------------------------------------
Could not synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.foo.supplier.vo.MenuVO
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1826)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2172)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:84)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
at com.foo.supplier.Hibernate.ItemDao.main(ItemDao.java:112)
Exception in thread "main" org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.foo.supplier.vo.MenuVO
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1826)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2172)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:84)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
at com.foo.supplier.Hibernate.ItemDao.main(ItemDao.java:112)

---------------------------------------------------------------------

my VO and hbm code are ---

public class ItemVO implements Serializable{

private long itemId;
private MenuVO menuId;
private SubmenuVO subMenuId;
//setters and getters for above }



<hibernate-mapping>
<class name="com.foo.vo.ItemVO" table="t_item">
<id name="itemId" column="Itemid" length="45">
<generator class="increment"/>
</id>

<many-to-one name="menuId" class="com.foo.supplier.vo.MenuVO" column="menuid" not-null="true" />
<many-to-one name="subMenuId" class="com.foo.supplier.vo.SubmenuVO" column="T_SubMenu_submenuid" not-null="true"/>

</class>

</hibernate-mapping>



public class MenuVO
{
private Integer menuId;
//setters and getters

}


<hibernate-mapping>
<class name="com.foo.vo.MenuVO" table="t_menu">
<id name="menuId" column="idT_Menu " length="45">
<generator class="increment"/>
</id>



</class>
</hibernate-mapping>



public class SubmenuVO {

private int subMenuId;
//settes and getters}

<hibernate-mapping>
<class name="com.foo.vo.SubmenuVO"
table="t_submenu">
<id name="subMenuId" column="submenuid" length="45">

<generator class="increment" />
</id>
</hibernate-mapping>



here im trying keep the id values of menu and submenu in Item ,
 
Don't get me started about those stupid light bulbs.
 
subject: Could not synchronize database