• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using Hibernate in a web application

 
author
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all!
I'm starting my first project using Hibernate.
I have to use it in a Web application that uses Struts as Framework.
I'd like to have some advice about how to pass DB Data to JSP for displaying rows.
In other words, should I pass the "live" Hibernate Object (that maps the DB column) directly to the JSP. (With the <jsp:useBean> for example) and the JSP browses the object.
Or should I create a ValueObject (a copy of the Hibernate Object) and pass it to the JSP ?
Which is the best practice ?
Thanks
Francesco
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U might want to keep your hibernate objects out of the form objects of struts.
It is always a good practice to keep your UI layer away from the business layer, It will give you more control when a client requirement changes or business requirement changes.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"satish ranch user"

Welcome to JavaRanch!

Can you please update your display name so it complies with our Naming Policy. You can do this here.

Thanks!
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate 'table representation' beans are just plain JavaBeans, so I cannot think of a reason not to use them for presentation purposes.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Francesco Marchioni:
Hi all!
I'm starting my first project using Hibernate.
I have to use it in a Web application that uses Struts as Framework.
I'd like to have some advice about how to pass DB Data to JSP for displaying rows.
In other words, should I pass the "live" Hibernate Object (that maps the DB column) directly to the JSP. (With the <jsp:useBean> for example) and the JSP browses the object.
Or should I create a ValueObject (a copy of the Hibernate Object) and pass it to the JSP ?
Which is the best practice ?
Thanks
Francesco



Will these objects be serialized? Is it just for display or any modification?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A major problem with ORM frameworks trying to pass objects out to the display layer is that the persistable objects often carry some extra freight related to the persistency mechanism - specifically, JDBC connection objects. This information generally gets ripped loose by the time the display layer gets it, so indirect refences like <c ut value="${object1.object2.property1}"/> end up failing or showing as null objects.

To function properly, you have to ensure that all the dependent items are force-fetched. That way, they can be located without reference to the persistency subsystem. Since lazy fetching is the norm, you may have to "nudge" the object structure to get everything resolved in the pre-display code while the persistency infrastructure is still active.

JDO can be a real pain in that regard. Hibernate often handles things more gracefully, but even it needs some manual help at times.

Just in case it wasn't clear, the answer is "yes. IF...".
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also use the Session In View pattern to have the Session available to the jsp page so that it can lazy load and load at time of view creation.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic