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: hibernate access entity's getter method
PostPosted: Wed May 30, 2007 12:36 am 
Newbie

Joined: Wed May 30, 2007 12:16 am
Posts: 1
There is a entity, one of its getter method has the code below:

return (Date) fromDate.clone();

when a new entity is created, fromDate attribute is null, invoking this getter method will cause nullpointexception,

But I do not know why hibernate invokes this getter method on a newly created entity, I got the nullpointexception when I called session.merge() to save this entity, I also do not know why hibernate need to create a new entity.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 2:35 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi spencers,

You could control setter getter or by field by using access="field|property|ClassName" with property.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 8:01 am 
Newbie

Joined: Thu May 17, 2007 5:29 am
Posts: 13
I don't think setting access="field" is a good idea, as you'll have to make fields public.
It would be simpler to add an if not null check.

Also, although I haven't tried this so can't say with certainty, I think you might end up with a TransientObjectException when the fromDate is present in you object as you are returning a new instance of date, not the one referred by fromDate.

_________________
--
Saugata
Please rate if this post helps


Last edited by saugata on Fri Jun 01, 2007 8:02 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 8:02 am 
Newbie

Joined: Thu May 17, 2007 5:29 am
Posts: 13
Sorry, pressed post twice :(

_________________
--
Saugata
Please rate if this post helps


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.