• 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

Hiberanate loaded values not displayed in JSP page

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Data Transfer Object which contains a User object. The User object is loaded by hibernate.


User class contains Profile class.


I create a Collection of SomeDTO objects and pass it to a JSP which renders them using a displaytag.
The User class is lazy loaded by hibernate.

The displaytag is used to show a list of users in table form.
The problem is for the mostly recently created user, the profile name column is not getting displayed in the table rendered by displaytag. A refresh of the page shows the profile name correctly.

Here is the JSP


The display problem occurs only for variables that are sub referenced. It does not happen when displaying String,Integer variables contained by User itself. Also the issue is with the latest row added through hibernate.


Why is this happening ? Has anyone else encountered this behavior before ?

[ June 26, 2007: Message edited by: Naveen Sampra ]
[ June 26, 2007: Message edited by: Naveen Sampra ]
 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I debugged this issue and here is something "strange" I found.

The issue is nothing to do with displaytag or the JSP page. It's to do with the way hibernate is loading the objects.

My JSP page contains a user list. An item from the list can be edited and the list is refreshed.

The user edit code is as follows:


After updating the DB is queried for users as follows:


After the table update the user is forwarded to the listing screen. So the update + list display is part of a single Http request. I'm using OpenSessionViewFilter and lazy loading.

The "strange" behavior I noticed is that while inspecting the List returned by criteria.list() above, all the User objects have proxy objects to reference Profile object, except for the recently edited User object. The profile variable is referencing a detached Profile object that is not initialized.

I hope I explanined clearly. Any idea what's going on ?
 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any suggestions/explanations ?

Let me make the question simpler.

Entity instances retrieved by a query are in persistent state. How is it that one of the instances(corresponds to the entity modified previously), is different to the others in the List. What I mean by "different" is that it has identifier value, but the remaining fields are not initialized.

Thanks.
 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No one seems to be answering. Question too complicated?

Here is another attempt:


Hibernate version:
Hibernate 3.2.1


Name and version of the database:
Oracle 10g

I perform the following operations:

Service method callA()
1) load a object using session -
User user1 = session.get(User.class, id);

2) Modify some values
user1.setLastName("Rxxxxx");
session.update(user1);

Service method callB()
1) Retrive users
Criteria criteria =session.createCriteria(User.class);
//set the criteria
List<User> userList = criteria.list();

The userList above contains modified user in callA() - i.e user1. Going through "userList" using debugger I find that all instances in the list are initialized properly except the modified user in callA(). The id field of user1 is initialized correctly but fields like firstName, lastName etc are null.

As a result when I display the list of users in the JSP page, some attributes of user1 are displayed as null. When I request for user listing (i.e service callB() only) they all get displayed correctly.

What's going on ?

I'm using Spring transaction mgmt/ OpenSessionViewFilter and lazy loading. Service callA() and callB() are part of the same request.

Can someone please help. This is urgent.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your are doing update and listing in a single transaction.the hibernate change object in memory but not in database.
 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm! in that case why is the listing showing null valued fields for the object. I would expect the old values at least.
reply
    Bookmark Topic Watch Topic
  • New Topic