-->
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: Best pratices with classes
PostPosted: Mon Sep 06, 2004 5:14 am 
Beginner
Beginner

Joined: Thu Mar 18, 2004 8:11 am
Posts: 38
Location: Italy
Hi all,

I got a question about best pratices in database objects loading using Hibernate.

I have a db with some tables and some relations among them. These tables map to java classes as appropriate. I would like to have the ability to load these classes from the db through static methods in them, ie:

class a {
public static a getByName(String name) {
... hibernate code to load the instance of a ...
}
}

Also, since the relations between tables are somehow complex, I also would like to load instances of my classes from class methods throug, i.e., an hibernate 'find' and the like.

class a {
public static List getASubsetOfARelation(...) {
... some session.find() here...
}
}

In the first case I have the feeling that the static method would need to have a net.sf.hibernate.Session parameter added, in order to let me specify the session on which I would like to execute the load, but in the latter I would like to use the very same session that actually loaded the 'a' object, without having to specify it. I can't find a way to do so, is there anything that may suffice?

I'm I wrong in trying to define static methods to load instances of my classes?

Thanks for your help,

_________________
Giampaolo Tomassoni
Italy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 5:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
it is better not to mix data access with domain model.

About using the same session.... the best you can do is only using the session stored in threadlocal.

Why aren't you using DAO layer?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 9:12 am 
Beginner
Beginner

Joined: Thu Mar 18, 2004 8:11 am
Posts: 38
Location: Italy
anthony wrote:
it is better not to mix data access with domain model.

About using the same session.... the best you can do is only using the session stored in threadlocal.

Why aren't you using DAO layer?


The fact is that I identified PostgreSQL as my RDBC, Hibernate as my persistence layer and I would like to get things simple, without splitting my app in a lot of layers which, in my case, I believe are useless: the resulting app would be something embeddable in a well-defined anvironment, so I would like to avoid to implement all the design patterns suggested by the j2ee guys.

I would like to implement the DAO layer in the DTO objects, also because the pure-DAO logic to implement is really minimal.

Do you think I'm completely out?

Thanks,

_________________
Giampaolo Tomassoni
Italy


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.