-->
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.  [ 4 posts ] 
Author Message
 Post subject: Lazy fetching and propagating data to a web tier
PostPosted: Fri Mar 31, 2006 5:43 am 
Newbie

Joined: Wed Jan 18, 2006 2:19 pm
Posts: 14
Hi. I have a model layer written with hibernate, and I have for example entities

Code:
public class ClassA{
  Integer id;
  String name;
  ClassB reference; //lazily fetched
}

public class ClassB{
  Integer id;
  String someString;
}


and I want to have a web tier independet to the business code, so I don't open a session for the request to avoid hibernate code there. Instead, I open the session in each method in the model layer.

Now, i want to render table in the web tier with atributes ClassA.name, ClassB.someString. I'd like to ask what is the best practics to do this. Should I have a data trasfer object for each such table with the attributes of several entities?
The example with two classes I wrote is pretty simple, but I can have many classes or collections lazily fetched this way.

I hope i didn't describe the problem too confusedly to understand..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 11:23 am 
Newbie

Joined: Fri Mar 31, 2006 11:11 am
Posts: 2
Location: Mannheim, Germany
I would use the model entities as detached objects in the web view and let your business classes ensure, that the proxies are fully initialized with Hibernate.iniitialize(Object o). I always try to avoid DTOs as these lead to duplicated code. But of course, in some environments, they are necessary, for example, if the web tier resides on a different machine and cannot directly use the model entities.


Top
 Profile  
 
 Post subject: DTOs...
PostPosted: Fri Mar 31, 2006 2:53 pm 
Newbie

Joined: Mon Aug 15, 2005 7:53 pm
Posts: 8
Location: Córdoba, Argentina
Hi kaiec
I'm using the same architecture:

JSP -> Struts -> Busines Objects (business logic) -> DTOs -> DAOs -> Hibernate -> Oracle

So I'm using DTOs to transfer data among layers... The DAO layer is responsible for converting Hibernate POJOs to TOs, of course it has a performance cost, but not very high.

I choose this way of doing things 'cause I didn't want business tier to know anything about persistence tier. So I would change hibernate to another persistence mechanism without changing any logic.
The view tier doesn't know anything about persistence either.

The DAO layer creates TOs and initializes them with the hibernate POJO values. It also initializes dependant objects... so the TOs graphs looks almost the same as the Hibernate POJO model.

I hope this helps

Regards,
Matías


Top
 Profile  
 
 Post subject: DTOs
PostPosted: Tue Sep 26, 2006 9:21 am 
Newbie

Joined: Wed Jan 18, 2006 2:19 pm
Posts: 14
Ok, as far as I know, DTO is the most common pattern to solve this problem. I thing this is a good idea to use hibernate pojos as DTOs and fill them according to needs in business logic or presentation to avoid duplicating code by creating new DTOs. Do you think that it's too messy to provide several similar functions in DAO which differ only in the degree of filled data?
For example functions
Code:
MyHibPojo getter1() {
  // returns only MyHibPojo with no fetched data
}

MyHibPojo getter2() {
  // returns MyHibPojo with prepared association data because it will be needed in business logic
}


I'm now working on some project where lots of code is written, but there's no lazy fetching and thus some performace problems appear. I need to solve this situation with the less possible impact to existing code. (Don't know whether it helps, but transaction demarcation is made in DAO layer via the Spring framework.)

thx, libor


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.