-->
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.  [ 14 posts ] 
Author Message
 Post subject: Session and Transaction
PostPosted: Wed Mar 17, 2004 11:14 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
Hi,

Code:
Session s = sessionFactory.openSession();
Transaction t = s.beginTransaction();
...


Do i need to close the session after committing the Transaction?

I want to make sure i have new Session for each call.

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You must close any opened session. It has a JDBC connection underneath

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:30 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
emmanuel wrote:
You must close any opened session. It has a JDBC connection underneath


I know, but i wasn't sure if trans.commit(); is closing session.

Thanks

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what architecture do you have?
using struts for example?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:36 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
delpouve wrote:
what architecture do you have?
using struts for example?


struts actions --> delegate class --> db layer

I don't want to manage sessions in servlet because in the future we my change it to:

struts action--> delegate class --> ejb --> db layer

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://www.hibernate.org/43.html

if you don't want to use a servlet filter, no problen you can reuse threadlocal concept, it's very usefull to manage sessions.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:51 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
delpouve wrote:
http://www.hibernate.org/43.html

if you don't want to use a servlet filter, no problen you can reuse threadlocal concept, it's very usefull to manage sessions.


I used threadlocal but had some session problems so i decided to open new session in every db layer method.

I am not sure i found yet the right solution to the session management.

I have problems when i try to work with objects that have childs.

When i try for example to save an object that holds a collection of other objects i get exceptions about session etc.

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
were you doing this:

get session from threadlocal (via static method)
session. find, query.list .... for example
modifying your persistent objects
comit


or:
get session from threadlocal (via static method)
session. find, query.list .... for example
session.disconnect or close
modifying your persistent objects
getting the session again
commit


?
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 12:03 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
delpouve wrote:
were you doing this:

get session from threadlocal (via static method)
session. find, query.list .... for example
modifying your persistent objects
comit


or:
get session from threadlocal (via static method)
session. find, query.list .... for example
session.disconnect or close
modifying your persistent objects
getting the session again
commit


?
[/b]


The first

Code:
Session s = sessionFactory.openSession();
Transaction t = s.beginTransaction();
s.save(object);
s.close();


object holds collection of childs. If i don't set inverse="true" in the map decleration i get an exception. The problem is that in this way the childs are not saved so i need to save them my self.

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Inverse="true" is not related at all with cascading.
use caascade="save-update"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 1:44 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
emmanuel wrote:
Inverse="true" is not related at all with cascading.
use caascade="save-update"


Well i don't know, I saw somwhere that i must set it to true when working with one-to-many relation. So what the purpose of inverse?

I tried setting caascade to "all" but still childs were not saved.

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 4:22 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://www.hibernate.org/155.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 4:30 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
delpouve wrote:
http://www.hibernate.org/155.html


Thanks for your efforts

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 4:35 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hope this helped you

Anthony


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