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: Hibernate used as non-persitent engine
PostPosted: Fri Jun 23, 2006 12:06 pm 
Beginner
Beginner

Joined: Mon Jun 19, 2006 9:21 pm
Posts: 25
Hi, so I've been trying to figure out how to do this effectively with hibernate since I love the mapping features it has and the transparent mapping to various databases. I will be using this with a largly already built system that doesn't use hibernate at all. The program will eventually have parts running on three different servers (security concerns) and so the database will be changing all the time, for every table (and I'm not exaggerating...every single table will be used by at least two servers) making it impossible for me to use persistence. So my question is, can I use hibernate as a non-persitence ORM?
If I can't, could anyone suggest a non-persistent ORM that has the same capability of hibernate in relation to it's mapping and database transparency.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 5:41 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
What do you mean by "non persistent ORM tool" ? It doesn't seem to make sense for me...

Looking at what you say, I need more explanations.

Do you want to only access the db without modifying, or maybe you just want to be able to do some kind of JDBC with table names and columns easily changeable ? If so, I'm not sure you should even think about a tool like Hibernate.

But let's let you precise your needs. It will be more simple to answer. Could you try and "refactor" your question ? :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 6:04 pm 
Beginner
Beginner

Joined: Mon Jun 19, 2006 9:21 pm
Posts: 25
Yeah...actually, it turns out I was thinking about persistence wrong. I was initially under the impression that persistence meant that the classes persist through the web pages always (ie. even when you say session.close() ). I guess it really means that it persists as long as the specific session being used stays open, which is fine...I think. Sorry for the extreme newb question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 6:23 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Well, no problem for the question.

Actually, the classes are persisted when you call session.flush(). Most of the time, you do it inside a transaction context, which you can start via the session.beginTransaction() method.

Typically, as explained in the javadoc of the Session class, here is the classical way of doing things (http://www.docjar.com/docs/api/org/hibe ... ssion.html):
Code:
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}


In the context of a web app, you've got multiple patterns for handling your session object, one of them is using a servlet filter. This pattern is called "open session in view" : http://www.hibernate.org/43.html
--
Baptiste
PS : don't forget to give credits on the left if you found this answer useful :)


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.