aspose file tools*
The moose likes Object Relational Mapping and the fly likes Can Hibernate be used to add records to a table? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Can Hibernate be used to add records to a table?" Watch "Can Hibernate be used to add records to a table?" New topic
Author

Can Hibernate be used to add records to a table?

Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53
Hello,

I'm developing a web app to create and track work orders. I've got the basic framework constructed using Hibernate and JSF in Netbeans. I've successfully created a few JSF pages which display records from a small MySQL database table. I am at the stage now where I would like to add a record to my table.

Would anyone happen to know if Hibernate can be used to add a record to a table based on user input? The documentation I've read seems to suggest that HQL only allows an INSERT from another table.

Any thoughts or suggestions would be welcome. Thank you.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes, you can use HQL to perform updates, however normally you would not do this because it sidesteps a lot of the benefits of Hibernate. You would use Hibernate's normal save method instead. Why is it HQL you want to use?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53
Hi Paul,

Thanks for the speedy reply. I'm still new to Hibernate and was not aware of the save method. I've located an example using save and am testing out some code based on that approach right now. I will let you know how it works out.
Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53
I've attempted to implement the Hibernate save method but I'm getting an "Error on Page" message. Here is the related code:

POJO


Helper method:



Controller method:



HTML

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What does the stack trace in the log say?
Jerry Goldsmith
Ranch Hand

Joined: Nov 29, 2006
Posts: 53
Nothing is written to the stack trace log.

I've enable logging in the Java control panel and re-directed the standard error output to a file. I've tested the re-direct by forcing a null pointer exception. The null pointer exception is written to the file but, when I remove it from the code, nothing shows up in the log.

I have incorporated log4j logging in my app and have placed an error level logger statement in my addJobCode method. INFO and DEBUG level messages are written but no ERROR level messages are written to the log.

The only error message I receive is "Error on page" at the bottom of my browser window. The addJobCode method fails to add a new record to my database table.

BTW: Sorry about adding this post to the Object Relational Mapping forum. I meant to post it to a JSF forum.

The addJobCode method:


The XML for the rendered page which displays the error:
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


The only error message I receive is "Error on page" at the bottom of my browser window.

Ah - so its a JavaScript error then, not a server error. You should probably try using Chrome or Firebug to see what is going on.


I have incorporated log4j logging in my app and have placed an error level logger statement in my addJobCode method. INFO and DEBUG level messages are written but no ERROR level messages are written to the log.

These are presumably being written to stderr rather than stdout.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can Hibernate be used to add records to a table?