this is my hbm file
Code:
<hibernate-mapping>
<class name="com.model.AccountImpl" table="account">
<id name="accountId" column="id">
<generator class="increment" />
</id>
<property name="name" column="name" />
<property name="description" column="description" />
<property name="active" column="active" />
<property name="code" column="code" />
<many-to-one name="parentAccount" column="parentId" class="com.model.AccountImpl"/>
<set name="children" cascade="save-update"
inverse="true" >
<key column="parentId"/>
<one-to-many class="com.model.AccountImpl"/>
</set>
</class>
</hibernate-mapping>
the description is AccountImpl class is mapped with a table named account having properties
parantAccount of type Account (in the same table )
set of accounts as children
in table some columns are
id is primary key
parentId is foreign key to the same table as this table have accounts that can be a parent account or child of some other account
thats why i put an object parentAccount of type AccountImpl and a set children having objects of AccountImpl in AccountImpl as hbm dipicts all
the issue is if from within application i call this with lazy="false" it fetches all of the records in account table coz of parent child relationship
but when i set lazy="true" or doest not set the lazy attribute.
from within application call it works but when i call the same function from dwl it throws an exception 'session closed or no session is available'
coz i am trying to get children on the basis of parentCode as
Code:
Session s = hibernateTemplate.getSessionFactory().openSession();
child = s.createCriteria(Account.class)
.createAlias("parentAccount","p")
.add(Restrictions.eq("p.code",code)).list();
s.close();
the exception is
Code:
ERROR [org.hibernate.LazyInitializationException] - failed to lazily initialize a collection of role: com.model.AccountImpl.children, no session or session was closed
as i m using hibernate with spring so i m using this filter
as
Code:
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>com.aedsys.service.FlushingSpringSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>