-->
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.  [ 4 posts ] 
Author Message
 Post subject: Cascade save problem
PostPosted: Thu Nov 25, 2004 10:07 am 
Newbie

Joined: Wed May 12, 2004 7:48 am
Posts: 5
Location: Belgium
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)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 10:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
show complete javacode (also add et remove child method)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 10:56 am 
Newbie

Joined: Wed May 12, 2004 7:48 am
Posts: 5
Location: Belgium
thanks for the fast reply!

I'm not sure what you mean by the remove child method. The objects I want to save are all new objects..

Here's the code in which I save the query to the db:

Code:
        Session session = HibernateUtil.getSession();
        try {
            Transaction tx = session.beginTransaction();
            log.debug("Saving Query "+query.getRow_id());
            session.saveOrUpdate(query);
            tx.commit();           
            session.close();
            return true;

        } catch (HibernateException e) {
            showError(e);
        }


Query, WhereItem and Subquery are simple dto's with some variables and some getters/setters (see the mapping files for the names of the variables).
The saving of a Query goes as planned when the WhereItems do not contain any Subquery..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 11:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you must be sure the associations are ok at both ends (many-to-one AND one-to-many)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.