-->
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.  [ 7 posts ] 
Author Message
 Post subject: MSQL+JDTS+Tomcat(struts) the session is new?
PostPosted: Tue Sep 21, 2004 3:12 am 
Newbie

Joined: Fri Oct 17, 2003 6:11 am
Posts: 15
Hibernate version:
I'm using MSQL+JDTS+Tomcat(struts)

I have a problem with sessions.

I put in the ServletContext the sessionsFactory and always call the opensessionmethod -> use the sessions -> finally close it.

Using my junit tests all works fine, but under Tomcat there are problems.

Hibernate tell me (with an Exception) that during the saveorUpdate method there are already object with the same identifier bind to it.

I check it but the session is "new", also I try by the method session.contains but it return false.

Very strange and my application don't work well.... :-(

Do you have any Ideas?
I'm using DBCP, no cache.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 21, 2004 3:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you don't give us enough details....
just know that tomcat + servlet filter to manage session via threadlocal pattern is the best solution

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 2:53 am 
Newbie

Joined: Fri Oct 17, 2003 6:11 am
Posts: 15
Yes....

I create the SessinFactory in a ContextListener and put it as ServletContext attribute.

In my doGet/StrutsActions I use it in this manner:

doGet()/axecuteStrutsActionMsthod {
.....
synch modelMethod (ServletContext) .....
....
}

modelMethod do intercat with the repository using Hibernate as:

synch modelMethod (ServletContext) {
.....
sessionfactory = ServletContext.getAttribute("factory");
....
Session .. = sessionfactory.openSession();
tx.begin;
......
..... ..... .....
finally session.close();
}

Do you think that the problem to find unexpected objects (with the same id) binds to the session can be due to a concurrent problem?

You suggest me to use thread local pattern ... i'm trying it.

Bye Bye


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 3:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
remind that hibernate session is not threadsafe

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 3:45 am 
Newbie

Joined: Fri Oct 17, 2003 6:11 am
Posts: 15
anthony wrote:
remind that hibernate session is not threadsafe


Yes Anthony I know it,
do you see that I use session in a non threadsafe manner? I' can't see it, Please Help telling me if you see it in my pattern.

I put here other info, to help you to understand what happen to my app.
I try to use the session.contains method but things are more strange here a code snip:

session = factory.openSession();
session.clear();
tx = session.beginTransaction();
Log.debug("session.contains(wobject):"+session.contains(wobject));

session.saveOrUpdate(wobject);
tx.commit();
session.close();

Here a snip of the log:
DEBUG PubblicationMain:? - session.contains(wobject): false
...
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 3, of class: it.rvspm.siscotel.portal.dao.News at net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:16

Do you have any ideas of what is the problem?

Thanks in advance
Stefano


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 8:44 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
is wobject
instance of
it.rvspm.siscotel.portal.dao.News ?

or is it a "child" or linked object?

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 3:20 am 
Newbie

Joined: Fri Oct 17, 2003 6:11 am
Posts: 15
anthony wrote:
is wobject
instance of
it.rvspm.siscotel.portal.dao.News ?

or is it a "child" or linked object?


Yes, I checked: dao.News is a linked object of wobject.
I put the
session.contains(wobject.getNews()),
but it answer "false" in the same manner it does for the wobject before.

I put below a snip of my mapping, in order to have your feedback if there are "links problems"
Thanks in advance
Stefano

<class name="it.rvspm.siscotel.portal.dao.WebObject" table="WEBOBJECT">
..... .....
<joined-subclass name="it.rvspm.siscotel.portal.dao.Page" table="PAGE">
<key column="id" foreign-key="pageId"/>
.....
<set name="pubblications" inverse="true" cascade="all" order-by="horizzontalposition asc">
<key column="page"/>
<one-to-many class="it.rvspm.siscotel.portal.dao.Pubblication"/>
</set>
<set name="subpages" >
<key column="superpage"/>
<one-to-many class="it.rvspm.siscotel.portal.dao.Page"/>
</set>
</joined-subclass>

<joined-subclass name="it.rvspm.siscotel.portal.dao.Content" table="CONTENT">
<key column="id" foreign-key="contentId"/>
.....
<set name="pubblications" inverse="true" cascade="all">
<key column="content"/>
<one-to-many class="it.rvspm.siscotel.portal.dao.Pubblication"/>
</set>
<joined-subclass name="it.rvspm.siscotel.portal.dao.Article" table="ARTICLE">
<key column="id" foreign-key="articleId"/>
<property name="body" type="text"/>
</joined-subclass>
<joined-subclass name="it.rvspm.siscotel.portal.dao.News" table="NEWS">
<key column="id" foreign-key="newsId"/>
<property name="body" type="text"/>
</joined-subclass>
</joined-subclass>

<joined-subclass name="it.rvspm.siscotel.portal.dao.Pubblication" table="PUBBLICATION">
<key column="id" foreign-key="pubblicationId"/>
....... .....
<many-to-one name="page" class="it.rvspm.siscotel.portal.dao.Page" />
<many-to-one name="content" class="it.rvspm.siscotel.portal.dao.Content"/>
</joined-subclass>


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