-->
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.  [ 1 post ] 
Author Message
 Post subject: problem with session and lazy loading
PostPosted: Fri Dec 14, 2007 1:49 pm 
Newbie

Joined: Tue Nov 27, 2007 6:11 am
Posts: 12
Hi,
I'm trying to write an application based on hibernate 3, I'm using the cglib2.1.3 and when I run my application I got the following exception:

Code:
Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - no Session
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
   at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
   at g2.database.mapping.Person$$EnhancerByCGLIB$$c482508f.getName(<generated>)
   at main.Main.main(Main.java:26)


The application is very simple: I've got a person table and a role table, and the following are the mappings:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="g2.database.mapping">
   <class
      name="Person"
      table="person"
   >
      <meta attribute="sync-DAO">true</meta>
      <id
         name="Id"
         type="string"
         column="personid"
      >
         <generator class="sequence"/>
      </id>

      <property
         name="Personpk"
         column="personpk"
         type="integer"
         not-null="true"
         length="10"
      />
      <property
         name="Name"
         column="name"
         type="string"
         not-null="false"
         length="20"
      />
      <property
         name="Surname"
         column="surname"
         type="string"
         not-null="false"
         length="20"
      />
      <property
         name="Borndate"
         column="borndate"
         type="date"
         not-null="false"
         length="13"
      />
      <property
         name="Phone"
         column="phone"
         type="string"
         not-null="false"
         length="50"
      />
      <property
         name="Mobilephone"
         column="mobilephone"
         type="string"
         not-null="false"
         length="50"
      />
      <property
         name="Fax"
         column="fax"
         type="string"
         not-null="false"
         length="50"
      />
      <property
         name="Email"
         column="email"
         type="string"
         not-null="false"
         length="50"
      />
      <property
         name="Web"
         column="web"
         type="string"
         not-null="false"
         length="100"
      />
      <property
         name="RecordDate"
         column="record_date"
         type="date"
         not-null="false"
         length="13"
      />
   


    <set name="roles" table="j_person_role" >
        <key column="personpk"/>
        <many-to-many column="rolepk"
            unique="true"
            class="Role"  />
    </set>

      

   </class>   
</hibernate-mapping>




<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="g2.database.mapping">
   <class
      name="Role"
      table="role"
   >
      <meta attribute="sync-DAO">true</meta>
      <id
         name="Id"
         type="integer"
         column="rolepk"
      >
         <generator class="sequence"/>
      </id>

      <property
         name="Roleid"
         column="roleid"
         type="string"
         not-null="true"
         length="50"
      />
      <property
         name="Rolerevision"
         column="rolerevision"
         type="java.lang.Long"
         not-null="true"
         length="10"
      />
      <property
         name="Description"
         column="description"
         type="string"
         not-null="false"
         length="100"
      />
      <property
         name="Revisioncomment"
         column="revisioncomment"
         type="string"
         not-null="false"
         length="100"
      />
      <property
         name="Creationdate"
         column="creationdate"
         type="date"
         not-null="false"
         length="13"
      />
      <property
         name="Revisiondate"
         column="revisiondate"
         type="date"
         not-null="false"
         length="13"
      />
   



   </class>   
</hibernate-mapping>


If I set all the classes and collection with lazy="false" the application works. Is there a way to use the lazy loading?

Thanks,
Luca


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.