• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using JSF with Hibernate?  RSS feed

 
Divya Yadav
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to insert student entries in to database(oracle) dynamically.In order to do that i am using JSF for form creation and validation and using ORM Framework Hibernate to store the entries to the database.I can create form page and write managed beans using of JSF but I wonder how to map JSF managed bean as a table in Database.can anyone guide me through any sample examples or any useful links,so that i can come to an idea.

Thanks for any help.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Divya!

Hibernate works very well with JSF, but not the way that you are thinking.

There are actually 2 different types of models involved in an app of this sort.

1. The Domain Model is the set of classes that represent persistent database objects (table data).

2. The GUI Model is the set of JSF backing beans used to hold the data displayed to and received from the user's GUI (browser).

Unfortunately, these two models have almost no overlap. GUI Model (backing bean) objects must be constructable from no-element constructors. Domain Model objects must (by definition) always have at least some pre-defined properties in order to be fetchable and persistable. Since JSF has no database capabilities itself, it basically cannot retrieve Domain Model objects and make them be backing beans.

You can, however, make Domain Model objects be properties of backing beans, since properties can be set/get after the backing bean is instantiated. So the paradigm is not this:

But this:


That way you can attach any person Entity instance you want as the "person" property of the personEdit UI (backing) bean.

I do a lot of this. In fact, I have quite a few apps that use the Spring Framework to manage the high- and low-level persistency-related services that fetch and store complex domain model object collections to be viewed and/or edited by JSF.
 
Divya Yadav
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You very much Mr.Tim.

I am trying to insert customer records into database using jsf and hibernate.I have tried with this code but something going wrong.Please have a look into my code:

input.jsp:




CustomerBean.java(Managed Bean)




Customer.java(Entity)



HibernateUtil.java




CustomerInsert.java



hibernate.cfg.xml:



hibernate.hbm.xml:



faces-config.xml:



web.xml:



I am getting the following Exceptions:




please tell me what would be the problem?? Thanks in advance.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid there's so much forest there that I cannot see trees. However, it does look like you have a Hibernate configuration problem. Hibernate doesn't have special configuration requirements for JSF, however. If you can set up a basic non-JSF webapp, the same settings also work for JSF.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!