Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Hibernate be used to add records to a table?

 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the stack trace in the log say?
 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic