Hi all,
I'm building a tool that allows the user to query a database. The users builds a query, runs it and gets a resultset. The query he builds should be saved in a database. That's what I'm using Hibernate for (and loving it!).
Now my problem.
The user creates a Query object, a Query object has several WhereItems, a WhereItem can have a Subquery, which has a Query, which has WhereItems,...
So:
Query -> WhereItem -> Subquery -> Query -> WhereItem -> ...
When I want to save the object, i use session.saveOrUpdate(query);
but that results in the exception shown below (TransientObjectException)
Anyone know what could be wrong?
Thanks in advance!
Hibernate version: Hibernate 2.1.6
Mapping documents:
Partial Query mapping
Code:
<hibernate-mapping>
<class name="com.lmsintl.its.aqt.dto.Query" table="AQT_Query">
<id name="row_id" column="row_id">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="description"/>
<list name="whereitems" inverse="true" cascade="all-delete-orphan">
<key column="query_id"/>
<index column="ordernr"/>
<one-to-many class="com.lmsintl.its.aqt.dto.WhereItem"/>
</list>
</class>
</hibernate-mapping>
Partial WhereItem mapping:
Code:
<hibernate-mapping>
<class name="com.lmsintl.its.aqt.dto.WhereItem" table="AQT_Query_Where">
<id name="row_id" column="row_id">
<generator class="identity"/>
</id>
<property name="logicaloperator"/>
<many-to-one name="leftsubquery" column="leftsubquery_id" cascade="all"/>
<property name="operator"/>
<many-to-one name="rightsubquery" column="rightsubquery_id" cascade="all"/>
</class>
</hibernate-mapping>
And the partial Subquery mapping:
Code:
<hibernate-mapping>
<class name="com.lmsintl.its.aqt.dto.Subquery" table="AQT_Subquery">
<id name="row_id" column="row_id">
<generator class="identity"/>
</id>
<many-to-one name="query" column="query_id" cascade="all"/>
<property name="correlation"/>
<property name="subquerynr"/>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:Code:
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.lmsintl.its.aqt.dto.Query
at net.sf.hibernate.impl.SessionImpl.throwTransientObjectException(SessionImpl.java:2768)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2760)
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:268)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2508)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2458)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2260)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)