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: