Hello
I am playing around with Hibernate 2.1.4 since this week and struggling, at the moment with the following problem: My HSQLDB 1.7.2rc6 contains one table ENTRY and the corresponding class Entry should build a double-linked tree-like structure, means each Entry object has a parent and some children.
After reading all entry objects and fill them up in a TreeModel, I would like to save changes made to one of them. So my ActionListener contains the following code:
Code:
entry.setText(EntryEditPanel.this.text.getText());
entry.setTimestamp(new Timestamp(new Date().getTime()));
try {
final Session session = HibernateUtils.currentSession();
final Transaction tx = session.beginTransaction();
session.save(entry);
tx.commit();
HibernateUtils.closeSession();
}
catch (HibernateException e1) {
e1.printStackTrace();
}
I don't understand why this throws the following exception (complete stack trace at the end):
Code:
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:
I am just trying to save the dirty instance. Which one is the transient instance meant by the exception?
-------------------------
Thanks for your help.
Daniel Frey
Attachments:Mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="ch.jfactory.projecttime.data.model">
<class name="DefaultEntry" table="ENTRY">
<id name="id" type="integer" unsaved-value="null">
<generator class="identity"/>
</id>
<version name="version" access="field"/>
<property name="text" type="string"/>
<property name="timestamp" type="timestamp"/>
<many-to-one name="parent" access="field"/>
<set name="children" inverse="true">
<key column="PARENT"/>
<one-to-many class="DefaultEntry"/>
</set>
</class>
</hibernate-mapping>
Complete stack trace:
Code:
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ch.jfactory.projecttime.data.model.DefaultEntry
at net.sf.hibernate.impl.SessionImpl.throwTransientObjectException(SessionImpl.java:2764)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2756)
at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66)
at net.sf.hibernate.type.EntityType.isDirty(EntityType.java:139)
at net.sf.hibernate.type.TypeFactory.findDirty(TypeFactory.java:225)
at net.sf.hibernate.persister.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:267)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2504)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2454)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2256)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2235)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at UseCase$2.actionPerformed(UseCase.java:193)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Configuration file for hibernate:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost/doc</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="dialect">net.sf.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.use_outer_join">true</property>
<mapping resource="DefaultEntry.hbm.xml"/>
</session-factory>
</hibernate-configuration>