-->
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.  [ 3 posts ] 
Author Message
 Post subject: Optional many-to-one relation....
PostPosted: Thu Mar 01, 2007 11:51 am 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
Hibernate version:
NHibernate 1.2.0.CR1

Mapping documents:

...
<many-to-one name="Person" column="PersonID" class="BLL.Person,BLL" cascade="none" />
...


In my BD the Foreign key PersonID is optional ...
So, sometimes I dont set the Person object ... And when I call saveOrUpdate I got the following error:

object references an unsaved transient instance - save the transient instance before flushing: BLL.Person

When I set the Person ID all works fine....

Any help
?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 9:17 am 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
any help???


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 10:50 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 11:26 am
Posts: 33
I realise this is an old post, but in case you are still waiting for a reply or it helps anyone else...

Whenever I have had this problem it is because the constructor I was calling created an instance of the referenced object, rather than setting it to null:

Code:
public class BD
{
    private Int64 id;
    private Person person;

    public BD()
    {
        this.person = new Person(); // Change this to this.person = null;
    }

    // Getters and setters etc ....

}


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