-->
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: problem using ThreadLocal pattern....
PostPosted: Thu Jun 22, 2006 11:50 am 
Newbie

Joined: Thu Jun 22, 2006 9:43 am
Posts: 2
Hi everybody.

I have written a sample application with the following 5 classes :

I want to access Report.Status, Report.Priority and Report.Type through Tickets.
i.e. Ticket.Report.Status, etc..
When I check Ticket.Report.Status.id I will get the id of Status as supposed to,
but when I try to check Ticket.Report.Status.desc, I will hit to the following exception :

Exception running task: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
I know that it’s because the session is closed, but i have access to primitive fields of Ticket.Report although the session is closed !
Also, notice that i used LazyLoading in none of the mapping files.

I’m using ThreadLocal pattern in my Persistor classes.

Is there anyone who can help me ?

Sincerely,

Narsis.

***************************

class Priority {
Long id;
String desc;

getId() {…}
setId() {…}

getDesc(){…}
setDesc() {…}
}



<class name="Priority"
table="PRIORITY"
>
<id name="id"
type="java.lang.Long"
column="ID"
>
<generator class="increment" />
</id>

<property name="desc"
type="java.lang.String"
column="DESCRIPTION"
/>
</class>
</hibernate-mapping>

***************************


class Type {
Long id;
String desc;

getId() {…}
setId() {…}

getDesc(){…}
setDesc() {…}
}


<class name="Type"
table="TYPE"
>
<id name="id"
type="java.lang.Long"
column="ID"
>
<generator class="increment" />
</id>

<property name="desc"
type="java.lang.String"
column="DESCRIPTION"
/>
</class>
</hibernate-mapping>

***************************

class Status {
Long id;
String desc;

getId() {…}
setId() {…}

getDesc(){…}
setDesc() {…}
}


<class name="Status"
table="STATUS"
>
<id name="id"
type="java.lang.Long"
column="ID"
>
<generator class="increment" />
</id>

<property name="desc"
type="java.lang.String"
column="DESCRIPTION"
/>
</class>
</hibernate-mapping>

***************************


class Report {
Long id;
Status status;
Priority priority;
Type type;

getId() {…}
setId() {…}

getStatus() {…}
setStatus() {…}

getType() {…}
setType() {…}

getPriority() {…}
setPriority() {…}
}


<class name="Report"
table="REPORT"
>
<id name="id"
type="java.lang.Long"
column="ID"
>
<generator class="increment" />
</id>

<many-to-one name="type"
class="Type"
>
<column name="FK_TYPE_ID" />
</many-to-one>

<many-to-one name="status"
class="Status"
>
<column name="FK_STATUS_ID" />
</many-to-one>

<many-to-one name="priority"
class="Priority"
>
<column name="FK_PRIORITY_ID" />
</many-to-one>

</class>
</hibernate-mapping>

***************************


class Ticket {
Long id;
Status status;
Report report;

getId() {…}
setId() {…}

getStatus() {…}
setStatus() {…}

getReport() {…}
setReport() {…}

}[/b]


<class name="Ticket"
table="TICKET"
>
<id name="id"
type="java.lang.Long"
column="ID"
>
<generator class="increment" />
</id>

<many-to-one name="report"
class="Report"
>
<column name="FK_REPORT_ID" />
</many-to-one>

<many-to-one name="status"
class="Status"
>
<column name="FK_STATUS_ID" />
</many-to-one>
</class>
</hibernate-mapping>


Quote:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 12:40 pm 
Beginner
Beginner

Joined: Thu Sep 01, 2005 7:43 am
Posts: 31
Location: León (Spain)
From hibernate docs (http://www.hibernate.org/hib_docs/v3/re ... pping.html), many-to-one section:

"(12) lazy (optional - defaults to proxy): By default, single point associations are proxied. lazy="no-proxy" specifies that the property should be fetched lazily when the instance variable is first accessed (requires build-time bytecode instrumentation). lazy="false" specifies that the association will always be eagerly fetched."

Bye.

_________________
Please rate...

Expert on Hibernate errors... I've had them all... :P


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 1:50 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
try setting lazy=false in ticket class mapping

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 25, 2006 10:50 am 
Newbie

Joined: Thu Jun 22, 2006 9:43 am
Posts: 2
I set lazy="false" in all of them, but nothing new has happenned!!!


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.