-->
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.  [ 2 posts ] 
Author Message
 Post subject: session disconnection in tomcat
PostPosted: Sat Jun 03, 2006 7:36 pm 
Newbie

Joined: Sat Jun 03, 2006 5:36 pm
Posts: 8
These problems occurs only when I'm using lazy collections.


Hibernate version: 3.1.3

Customer mapping:

<hibernate-mapping>
<class name="Customer" table="CUSTOMER">
<id name="id" column="CUSTOMER_ID">
<generator class="native"/>
</id>
<property name="firstName"/>
<property name="lastName"/>
<property name="company" not-null="true"/>

<bag name="notes" order-by="date desc" table="CUSTOMER_NOTES">
<key column="CUSTOMER_ID"/>
<many-to-many
column="NOTE_ID"
unique="true"
class="sk.akruks.kormoran.model.Note"/>
</bag>

<bag name="events" inverse="true">
<key column="CUSTOMER_ID"/>
<one-to-many class="Event"/>
</bag>
</class>
</hibernate-mapping>

Event mapping:

<hibernate-mapping>
<class name="sk.akruks.kormoran.model.Event" table="EVENT">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>

<many-to-one name="customer"
column="CUSTOMER_ID"
not-null="true"/>

<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="eventType"/>
<property name="eventTypeStr"/>
<property name="visitors"/>
<property name="note" type="text"/>
<property name="author"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Well I make my web application in Tomcat.
I used well knows HibernateUtil class, which does not work for my not lazy Bag.

When I try this:
Code:
getSession().beginTransaction();
p_event.setCustomer(customer);
customer.getEvents().add(p_event);       
getSession().save(p_event);
getSession().getTransaction().commit();


I get exception

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role

for this code:
Code:
getSession().beginTransaction();
Hibernate.initialize(customer.getEvents());
p_event.setCustomer(customer);
customer.getEvents().add(p_event);       
getSession().save(p_event);
getSession().getTransaction().commit();


I get this exception
org.hibernate.HibernateException: disconnected session
org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:452)
org.hibernate.Hibernate.initialize(Hibernate.java:295)


I tried also filter as mentioned on
http://www.hibernate.org/43.html

In that case I get:

javax.servlet.ServletException: Transaction not successfully started
sk.akruks.kormoran.utils.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:62)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


root cause

org.hibernate.TransactionException: Transaction not successfully started
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
sk.akruks.kormoran.utils.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:39)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


Name and version of the database MySQL 5.0.21
JDBC: mysql-connector-java-3.1.12

Only way for me was to set lazy="false" :(

Could anyone help me?
How can I keep session open?
Also openNew session is not working for me.
Should I use JTA? I'm newbie, I'm affraid I cannot handle it..


Top
 Profile  
 
 Post subject: lazy losing session
PostPosted: Thu Sep 21, 2006 5:06 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 12:09 pm
Posts: 20
Location: Belgium
Hello. Sorry I cannot be of help with your issue but did you ever get a resolution to this I am experiencing the same problem.

cheers
Martin


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