-->
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.  [ 2 posts ] 
Author Message
 Post subject: hibernate get and set methods
PostPosted: Mon Oct 20, 2008 6:12 pm 
Newbie

Joined: Wed Oct 15, 2008 11:51 am
Posts: 3
Need to know when get and set methods are being called :

I have a simple scenario :

I have a date field in database dateModified mapped to a field in my POJO

I have the following two methods :

private Date dateModified;

public void setDateModified(Date test)
{
this.dateModified = test;
}

public String getDateModified()
{
Format format = new SimpleDateFormat("MMMM, yyyy");
String cycleDate = format.format(dateModified);
return cycleDate;
}

I am getting error in the setter method when I try to pick data from the database. As I see it , select statement would only be on set method and get method does not have to do anything with the select statement. Correct me if I am wrong.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2008 7:55 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Don't try to map the string property, nor to retrieve it via SQL.
Remember that Hibernate basically transforms your HQL, Criteria or load() into an SQL statement. No way the SimpleDateFormat part can be transformed into SQL.

But once you have the bean validly loaded, you can call the string getter on it.

_________________
Gonzalo Díaz


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