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.javaCode:
/** 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!