-->
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.  [ 7 posts ] 
Author Message
 Post subject: Weird TransientObjectException?? Unjustified!
PostPosted: Tue Nov 18, 2008 2:04 pm 
Newbie

Joined: Tue Nov 18, 2008 1:52 pm
Posts: 4
Location: São Paulo, SP
Hello there.

I have a problem on working with Hibernate. Actually, I've being working with it for a year. I know why TransientObjectException occurs, but if you follow me, maybe you will agree when I tell you this is weird and unjustifiable.

I have a class named CityVO with is perfectly mapped. I also have a class named AddressVO which is defined basically as follows:

Code:
@Entity
@Table(name = "ADDRESS", uniqueConstraints = {})
public class AddressVO {
   private CityVO city;

    @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
    @JoinColumn(name = "FK_ID_CITY")
    public CityVO getCity() {
        if(isLazy() && this.city == null) {
            this.city = new CityVO();
        }

        return this.city;
    }

    public void setCity(CityVO city) {
        this.city = city;
    }
}


Just to justify, this isLazy() method exists because a particularity on my application requires me to do that.

Well, everything works just finde. The problem is I got a very complex data importation process from Excel and I am having this error message:

Quote:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: br.com.singlepoint.crm.vo.CityVO


I thought that in some moment, my isLazy() was returning true and creating an instance of CityVO. But this is not true: while debugging, I realized this error occurs when I call the save() and flush() methods on Session, passing my AddressVO instance, and this instance's city attribute is null.

As long as know, this situation can't throw TransientObjectException. But it does. So my question is: what should I do?

Since now, I thank you all.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 6:57 am 
Newbie

Joined: Tue Nov 18, 2008 1:52 pm
Posts: 4
Location: São Paulo, SP
Still trying...
Anyone can help?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 12:04 pm 
Newbie

Joined: Tue Nov 18, 2008 1:52 pm
Posts: 4
Location: São Paulo, SP
Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 12:48 pm 
Newbie

Joined: Wed Oct 08, 2008 1:54 am
Posts: 14
Are you sure that the isLazy() method cannot return 'true' when hibernate invokes the getCity() method during the invocation of save()? Have you checked the value of the city field after the exception occured?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 2:00 pm 
Newbie

Joined: Tue Nov 18, 2008 1:52 pm
Posts: 4
Location: São Paulo, SP
Indeed.

In my catch block, my city reference was null. I also put a breakpoint in the line where I create an instance of CityVO. But after I call save(), it seens not to step on it.

Thanks for the help. I am still trying.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 3:29 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Well, you're definitely getting a TransientObjectException. I'd put a breakpoint in the TransientObjectException constructor - you might see the offending parent and child objects.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 6:35 pm 
Newbie

Joined: Wed Oct 08, 2008 1:54 am
Posts: 14
It might also be that the fact the the city is null causes the Problem if the foreign key is defined as unique and/or not null ...


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