-->
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: Pesistence Of Simple Association
PostPosted: Sat Jul 26, 2008 8:37 am 
Newbie

Joined: Mon Mar 05, 2007 8:56 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1

Mapping documents:

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

<hibernate-mapping>
<class name="com.venture.hibernate.Bar" table="bar" dynamic-insert="true" dynamic-update="true">
<id name="barID" type="java.lang.Integer" column="barID" >
<generator class="increment" />
</id>
<property name="barName" type="string" update="false" insert="false">
<column name="bar_name" length="20" />
</property>

<set name="stocks" inverse="true">
<key column="barID"></key>
<one-to-many class="com.venture.hibernate.Stock"/>
</set>
</class>
</hibernate-mapping>

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

<hibernate-mapping>
<class name="com.venture.hibernate.Stock" table="inventory" >
<id name="stockID" type="java.lang.Integer" column="inventoryID" >
<generator class="increment" />
</id>
<property name="product" type="string" length="20">
<column name="productid"></column>
</property>
<property name="quantity" type="integer">
<column name="quantity"></column>
</property>

<many-to-one name="bar"
column="barID"
class="com.venture.hibernate.Bar"
/>
</class>
</hibernate-mapping>



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

session = createSession();
Transaction trans = session.beginTransaction();
session.save(stock);
trans.commit();
session.close();

Full stack trace of any exception that occurs:

Hibernate: select max(inventoryID) from inventory
Exception in thread "main" org.hibernate.TransientObjectException: com.venture.hibernate.Bar
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:221)
at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:476)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:2803)
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:467)
at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:190)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.venture.hibernate.SQLImpl.insertStockDetails(SQLImpl.java:15)
at com.venture.hibernate.Test.main(Test.java:20)


Name and version of the database you are using:

MySQL 5

The generated SQL (show_sql=true):

Hibernate: select max(inventoryID) from inventory

Debug level Hibernate log excerpt:

Problems with Session and transaction handling?

No

Read this: http://hibernate.org/42.html

_________________
Adnan Arab


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 27, 2008 11:31 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
public class TransientObjectException
extends HibernateException

Thrown when the user passes a transient instance to a Session method that expects a persistent instance.

http://www.hibernate.org/hib_docs/v3/api/org/hibernate/TransientObjectException.html

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.