-->
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: many-to-one/one-to-many/LazyInitializationException
PostPosted: Sat Jul 21, 2007 8:13 am 
Newbie

Joined: Sat Jul 21, 2007 7:46 am
Posts: 2
Hi,

First of all hello everyone since i'm new to this forum. I've been searching the topics for an answer to my problem, and haven't found but if i'm wrong don't slap too hard :)
Also, i'm a bit newbie to Hibernate :(

I'm experiencing the following shit for 2 days and can't find a solution :

<======= DATABASE ======>

This is the piece of database concerned :

I have a table Questionnaire, containing the fields:
q_id
and some stuff.... (like q_date_begin, q_date_end,...)

Another table Questions : (with an s)
q_id
q_id_questionnaire (foreigh key to Questionnaire.q_id)
q_id_question (foreign key to Question.q_id)


Another table Question : (without an s, sorry ^^)
q_id
and some stuff....



Let's juste be concerned about the link between Questionnaire and Questions :

<========= MAPPING =========>
I've used MyEclipse to generate Hibernate Mapping, which seems to be correct :

Questionnaire.hbm.xml :
<set name="questionses" inverse="true">
<key>
<column name="q_id_questionnaire" not-null="true" />
</key>
<one-to-many class="beans.Questions" />
</set>

Questions.hbm.xml :
<many-to-one name="questionnaire" class="beans.Questionnaire">
<column name="q_id_questionnaire" />
</many-to-one>



<========== JAVA CODE BETWEEN open and close session ===>

I don't need to provide any, the exception is thrown as soon as i access a property of the "questionses" Set (size() for isntance)


<======== EXCEPTION ============>

org.hibernate.LazyInitializationException: illegal access to loading collection
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
org.hibernate.collection.PersistentSet.size(PersistentSet.java:114)
com.excelplace.struts.action.EnqueteAction.execute(EnqueteAction.java:94) (NOTE : -> this is my access to size())
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



<========= LOG4J piece of trace =========>

2007-07-21 12:58:34 DEBUG [Printer] listing entities:
2007-07-21 12:58:34 DEBUG [Printer] beans.Questionnaire{QDateEnd=1985-08-10 12:58:45, questionses=<uninitialized>, QPicture=plop, QLogos=plop, QColors=plop, QDateBegin=1985-08-10 12:45:45, QId=1}
2007-07-21 12:58:34 DEBUG [Printer] beans.Questions{questionnaire=null, QNumQuestion=null, QJumpToNextPageAfter=null, QId=4, question=null}
2007-07-21 12:58:34 DEBUG [Printer] beans.Questions{questionnaire=null, QNumQuestion=null, QJumpToNextPageAfter=null, QId=1, question=null}
2007-07-21 12:58:34 DEBUG [Printer] beans.Questions{questionnaire=null, QNumQuestion=null, QJumpToNextPageAfter=null, QId=3, question=null}
2007-07-21 12:58:34 DEBUG [Printer] beans.Questions{questionnaire=null, QNumQuestion=null, QJumpToNextPageAfter=null, QId=2, question=null}

I think this piece of log is interesting :
I find it strange that in the beans.Questions entities, my questionnaire=null ?
If i remove the many-to-one mappings (and eventually replace them by Integer properties mappings), my beans.Questions will be filled by the database entries, the "questionses" attribute won't be uninitialized anymore, and everything will be OK, the size() call will print 4.
But in the current situation the size() call throws the exception.

I've read the hibernate reference documentation with bidirectional associations but my mapping is the very same... I really can't figure it out :(

I hope this is clear enough, any help will be very appreciated by my mates and i ^^


Hibernate version:
3.1

Name and version of the database you are using:
MySQL

Debug level Hibernate log excerpt:
DEBUG


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 21, 2007 11:17 pm 
Newbie

Joined: Sat Jul 21, 2007 11:01 pm
Posts: 3
here as i see you are trying to change the size of Set .
i dont think you can change the size of a set....

you can do some other thing access question from set and change any property in that.......

_________________
Ashish Gupta

Sr. System Analyst
India


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.