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: Hibernate Date Not Saved
PostPosted: Sat Jan 23, 2010 5:02 am 
Newbie

Joined: Sat Jan 23, 2010 4:38 am
Posts: 5
Hi Experts,

Click on "Save" button shows the same page without saving the data on database. Please help.


My web page source is as follows (JSF code):
<h:form>
<h:panelGrid border="1" columns="2">
<h:outputLabel value="Task: "></h:outputLabel>
<h:inputText value="#{projectBean.PName}""></h:inputText>
<h:outputLabel value="Status: "></h:outputLabel>
<h:selectOneMenu binding="#{statusBean.statusList}" value="#{projectBean.PSCode}""></h:selectOneMenu>
<h:outputLabel value="Commencement (Date): "></h:outputLabel>
<h:inputText value="#{projectBean.PCommDate}""></h:inputText>
</h:panelGrid>
<h:commandButton value="Save" actionListener="#{projectBean.save}"></h:commandButton>
</h:form>


My hibernate save method is as follows:

...
session.beginTransaction();
session.saveOrUpdate(projectInstance);
session.getTransaction().commit();
...


Top
 Profile  
 
 Post subject: Re: Hibernate Date Not Saved
PostPosted: Sat Jan 23, 2010 3:05 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Is there any JDBC printout or console messages?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Hibernate Date Not Saved
PostPosted: Sat Jan 23, 2010 4:44 pm 
Newbie

Joined: Sat Jan 23, 2010 4:38 am
Posts: 5
No JDBC printout. Log was saying Unknown Entity about my bean.
I forgot to add the new bean in the hibernate.cfg.xml (My mistake).

Thank you for the helping response.

Now I am looking for some improvements as:
1- I am logging the datestamp when record was saved or updated. So I am writing my relevant getter as below. Please confirm whether this is the right way for this in hibernate?

public Date getDatestamp() {
if(datestamp == null) {
return new Date();
} else {
return datestamp;
}
}

2- Some fields does not accept null by my design and if user don't give the values on the form, hibernate throws the exception on the consol. How to catch and display proper message on the UI for end user of the application?

Sorry for writing my second question in the same thread.


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.