-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: no tight coupling between GUI code and data access code
PostPosted: Thu Apr 06, 2006 8:15 pm 
Newbie

Joined: Fri Apr 01, 2005 8:45 pm
Posts: 17
We have a line drawn in the sand between our GUI code and our database access code. All calls from the GUI must go through an interface to retreive data so we never tightly couple the code. i.e. we could easily swap out the GUI for a text-only version of our app using the same interface. For example we might have GUI code like:

IDataManager manager = DataManagerFactory.createManager();
List<FooUser> list = manager.getUsers();

For (FooUser user : list) {
panel.add(new Label(user.getName());
}

// above code adds all the usernames as labels to a GUI panel

Inside the getUsers function of the DataManager implementation of IDataManger would be the hibernate code to open a session, select all the users from the database, and close the session.

This separation is great for code re-use but I run into problems with no-active hibernate session when trying to access fields in the POJO on the GUI side. The solution is to load all the fields before returning the POJO or have more methods in the interface to load the extra fields as needed.

But often I'll find myself passing in a POJO and calling session.get to load the object I already loaded! Does anyone else use this line-in-the-sand approach and have better ways?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 10:41 pm 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
Are the properties on the POJO other objects persisted by Hibernate? If so, set lazy="false" on the property assignments in the XML for the O/RM.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 07, 2006 12:53 am 
Newbie

Joined: Fri Apr 01, 2005 8:45 pm
Posts: 17
bslwh wrote:
Are the properties on the POJO other objects persisted by Hibernate? If so, set lazy="false" on the property assignments in the XML for the O/RM.


Sure, but I still end up having to re-load the POJO. For example, I get the entire object with lazy false, the GUI updates some of the fields. I want to call session.update on that object but I can't. I'd get a no active session error if I did. I have to call session.get first and "waste" an extra DB lookup.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.