-->
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: Could not synchronize database state with session
PostPosted: Sat Mar 08, 2008 7:04 am 
Newbie

Joined: Sat Mar 08, 2008 6:35 am
Posts: 4
Hi everybody :

i am facing the following issue:

object references an unsaved transient instance - save the transient instance before flushing



The Domain Classes


public class Company
{
private String companyName;
private Set dbdcCDeliveryAddress = new HashSet();

// setters and getters for this properties

}


public class DBDCDeliveryAddress {

private String receiverID;
private Company company;

// setters and getters for this properties

}


The following are the mapping files

<hibernate-mapping>
<class
name="com.db.caaa.domain.Company"
table="COMPANY"
dynamic-update="false"
dynamic-insert="false"
>
<cache usage="nonstrict-read-write" />

<id
name="id" column="id" type="long" unsaved-value="-1" >
<generator class="native">
</generator>
</id>

<property
name="companyName" type="java.lang.String" update="true" insert="true" access="property" >
<column
name="companyName"
length="35" unique-key="CONAMESNAME" not-null="true"
/>
</property>

<property
name="companyShortName" type="java.lang.String"
update="true" insert="true" access="property" >
<column
name="companyShortName"
length="20"
unique-key="CONAMESNAME"
not-null="true"
/>
</property>
<set
name="dbdcCDeliveryAddress"
table="DBDCDELIVERYADDRESS"
lazy="false"
inverse="false"
cascade="all"
sort="unsorted">
<cache
usage="nonstrict-read-write"
/>

<key
column="company_fk"
>
</key>

<one-to-many
class="com.db.caaa.domain.DBDCDeliveryAddress"
/>
</set>

</hibernate-mapping>
The following is another the mapping file:

<hibernate-mapping>
<class
name="com.db.caaa.domain.Company"
table="COMPANY"
dynamic-update="false"
dynamic-insert="false"
>
<cache usage="nonstrict-read-write" />

<id
name="id" column="id" type="long" unsaved-value="-1" >
<generator class="native">
</generator>
</id>

<property
name="companyName" type="java.lang.String" update="true" insert="true" access="property" >
<column
name="companyName"
length="35" unique-key="CONAMESNAME" not-null="true"
/>
</property>

<property
name="companyShortName" type="java.lang.String"
update="true" insert="true" access="property" >
<column
name="companyShortName"
length="20"
unique-key="CONAMESNAME"
not-null="true"
/>
</property>
<set
name="dbdcCDeliveryAddress"
table="DBDCDELIVERYADDRESS"
lazy="false"
inverse="false"
cascade="all"
sort="unsorted">
<cache
usage="nonstrict-read-write"
/>

<key
column="company_fk"
>
</key>

<one-to-many
class="com.db.caaa.domain.DBDCDeliveryAddress"
/>
</set>

</hibernate-mapping>

Can please resolve this. Thanks in advance:


Last edited by sreenu on Mon Mar 10, 2008 3:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 7:18 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Lots of stuff you presented here - but what's your question and problem?


Top
 Profile  
 
 Post subject: Need help to resolve issue wih Hibernate
PostPosted: Mon Mar 10, 2008 3:09 am 
Newbie

Joined: Sat Mar 08, 2008 6:35 am
Posts: 4
carlolf wrote:
Lots of stuff you presented here - but what's your question and problem?

To be brief, i am getting the following exception.
object references an unsaved transient instance - save the transient instance before flushing


Plz see the domain files below:

Code:
public class Company
{
     private long id;   
     private String companyName;
     private Set dbdcCDeliveryAddress = new HashSet(); 
   
// setters and getters for this properties
   
}


public class DBDCDeliveryAddress {
      private long id;
      private String receiverID;
     private Company company;

// setters and getters for this properties

}


Code:
[color=red]
[b]Company Mapping File[/b]

<hibernate-mapping>
    <class
        name="com.db.caaa.domain.Company"
        table="COMPANY"
        dynamic-update="false"
        dynamic-insert="false"
    >
        <cache usage="nonstrict-read-write" />

        <id
            name="id" column="id"   type="long"   unsaved-value="-1"  >
            <generator class="native">
            </generator>
        </id>

        <property
            name="companyName"    type="java.lang.String"  update="true"  insert="true"  access="property" >
            <column
                name="companyName"
                length="35" unique-key="CONAMESNAME" not-null="true"
            />
        </property>

        <property
            name="companyShortName"  type="java.lang.String"
            update="true"  insert="true"  access="property" >
            <column
                name="companyShortName"
                length="20" 
            unique-key="CONAMESNAME"
                not-null="true"
            />
        </property>
        <set
            name="dbdcCDeliveryAddress"
            table="DBDCDELIVERYADDRESS"
            lazy="false"
            inverse="false"
            cascade="all"
            sort="unsorted">
            <cache
                usage="nonstrict-read-write"
             />

              <key
                  column="company_fk"
              >
              </key>

              <one-to-many
                  class="com.db.caaa.domain.DBDCDeliveryAddress"
              />
        </set>
   
</hibernate-mapping>

[/color]

Code:

[color=orange][/color][color=green]
[b]DBDCDEliverAddress Mapping File[/b]

<hibernate-mapping>
    <class
        name="com.db.caaa.domain.DBDCDeliveryAddress"
        table="DBDCDELIVERYADDRESS"
        dynamic-update="false"
        dynamic-insert="false" >
        <cache usage="nonstrict-read-write" />

        <id
            name="id"
            column="id"
            type="long"
            unsaved-value="-1"
        >
            <generator class="native">
            </generator>
        </id>

         <property
            name="receiverID"
            type="java.lang.String"
            update="true" insert="true" access="property">
            <column
                name="ReceiverId"  not-null="false"  unique="false"/>
        </property>

     
       <many-to-one
            name="company"
            class="com.db.caaa.domain.Company"
            cascade="save-update"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="company_fk"
        />
           
    </class>

</hibernate-mapping>

[/color]




Could please look into this and suggest me to resolve his issue:
Thanks in advance


Top
 Profile  
 
 Post subject: Re: Could not synchronize database state with session
PostPosted: Wed Mar 12, 2008 3:54 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
sreenu wrote:
object references an unsaved transient instance - save the transient instance before flushing


I guess the problem comes from an instance of your Company class; I think you have to load the instance which is referenced by a [i]DBDCDeliveryAddress[(i] instance it into your session.

Carlo
-------
don't forget to give credits


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.