-->
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: Need help: org.hibernate.LazyInitializationException
PostPosted: Sun Nov 06, 2005 10:11 am 
Newbie

Joined: Sat Nov 05, 2005 8:59 pm
Posts: 16
Hallo all, i have two class with bidirectional one to many association

Customer [1..1] <->CustomerCard[0..*]

The codes and annotations like this:

Customer.java
Code:
   
/** Implements the getter for + cards : Set(CustomerCard)
    */
   @OneToMany(targetEntity=CustomerCard.class, cascade=CascadeType.ALL,
         mappedBy ="owner" , fetch = FetchType.EAGER)
   public Set getCards() {
      if ( f_cards != null ) {
//         return Collections.unmodifiableSet(f_cards);
         return this.f_cards;
      } else {
         return null;
      }
   }
   


CustomerCard.java
Code:
/** Implements the getter for owner customer
    */
   @ManyToOne(cascade=CascadeType.ALL , fetch = FetchType.EAGER)
   @JoinColumn(name="CUSTOMER_ID", nullable=false)
   public Customer getOwner() {
      return f_owner;
   }


I can save object in table but when i retrieve data from database, i got exceptiong:
Code:
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of example.Customer.setCards
   at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:215)
   at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:185)
   at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3231)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:126)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
   at org.hibernate.loader.Loader.doQuery(Loader.java:717)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1782)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2729)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:809)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:749)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:742)
   at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:105)
   at bussiness.Business.showAllCustomers(Business.java:140)
   at bussiness.Business.printMenuProcess(Business.java:117)
   at bussiness.Business.main(Business.java:56)
Caused by: net.sf.cglib.beans.BulkBeanException: illegal access to loading collection
   at example.Customer$$BulkBeanByCGLIB$$e917e276.setPropertyValues(<generated>)
   at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212)
   ... 22 more
Caused by: org.hibernate.LazyInitializationException: illegal access to loading collection
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)
   at example.Customer.setCards(Customer.java:109)
   ... 24 more


then i switched the hibernate.cglib.use_reflection_optimizer to false in persistence.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<entity-manager>
    <name>context</name>
    <class>example.Customer</class>
    <class>example.CustomerCard</class>


    <properties>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/onetomany"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.password" value=""/>
        <property name="hibernate.connection.username" value="Xinhua"/>
        <property name="hibernate.cglib.use_reflection_optimizer" value= "false"/>

    </properties>
</entity-manager>


But it does not help, the exceptions are the same.

How can i fix the problem?
Any tips and help would be appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 06, 2005 11:32 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
This exception usually occures when you are trying to set a null value to primitive type.

Example: set null to int variable

It cannot set 0, since that might be missleading.
Change type to object type - Integer.


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.