-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-one: "Exception initializing proxy"
PostPosted: Wed Dec 03, 2003 11:33 am 
Newbie

Joined: Wed Dec 03, 2003 11:15 am
Posts: 13
Location: Stuttgart, Germany
Hi @ all

Following sitation: Database with 2 tables: "customer" and "product_order".
Table "product_order" has a column "customer_id" that refrences the column
"id" in table customer. The column "customer_id" may be "null". And thats
where the problem is. I got 3 rows in the table "product_order", and one
of those has a "null" value in the column "customer_id". When my program comes
to that row, it terminates with the following error:

###
03.12.2003 16:28:00 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1 rc1
03.12.2003 16:28:00 net.sf.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=abill, hibernate.connection.password=, hibernate.cglib.use_reflection_optimizer=false, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://ipcabi01/hibernate, hibernate.connection.show_sql=true, hibernate.connection.driver_class=org.gjt.mm.mysql.Driver}
03.12.2003 16:28:00 net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: com/iag/ProductOrder.hbm.xml
03.12.2003 16:28:01 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: com.iag.ProductOrder -> product_order
03.12.2003 16:28:01 net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: com/iag/Customer.hbm.xml
03.12.2003 16:28:01 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: com.iag.Customer -> customer
03.12.2003 16:28:01 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
03.12.2003 16:28:01 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: com.iag.Customer.ProductOrder -> product_order
03.12.2003 16:28:01 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
03.12.2003 16:28:01 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
03.12.2003 16:28:01 net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.MySQLDialect
03.12.2003 16:28:01 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
03.12.2003 16:28:01 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
03.12.2003 16:28:01 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
03.12.2003 16:28:01 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://ipcabi01/hibernate
03.12.2003 16:28:01 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=abill, password=, show_sql=true}
03.12.2003 16:28:01 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
03.12.2003 16:28:02 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
03.12.2003 16:28:02 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC 2 max batch size: 15
03.12.2003 16:28:02 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
03.12.2003 16:28:02 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.ehcache.hibernate.Provider
03.12.2003 16:28:02 net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
03.12.2003 16:28:02 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
03.12.2003 16:28:02 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: no JNDI name configured
03.12.2003 16:28:03 net.sf.hibernate.proxy.LazyInitializer initializeWrapExceptions
SCHWERWIEGEND: Exception initializing proxy
net.sf.hibernate.PropertyAccessException: Exception occurred inside setter of com.iag.ProductOrder.Customer
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:49)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:216)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2132)

at net.sf.hibernate.loader.Loader.doQuery(Loader.java:235)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:128)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:826)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:846)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:420)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2039)
at net.sf.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:1857)
at net.sf.hibernate.proxy.LazyInitializer.initialize(LazyInitializer.java:49)
at net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitializer.java:56)
at net.sf.hibernate.proxy.LazyInitializer.getImplementation(LazyInitializer.java:156)
at net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:72)
at com.iag.ProductOrder$$EnhancerByCGLIB$$32b889cd.getProductCategory(<generated>)
at ShowProductOrders.main(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
... 17 more
Caused by: java.lang.NullPointerException
at com.iag.ProductOrder.setCustomer(Unknown Source)
... 22 more
Exception in thread "main" net.sf.hibernate.LazyInitializationException: Hibernate lazy instantiation problem
at net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitializer.java:60)
at net.sf.hibernate.proxy.LazyInitializer.getImplementation(LazyInitializer.java:156)
at net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:72)
at com.iag.ProductOrder$$EnhancerByCGLIB$$32b889cd.getProductCategory(<generated>)
at ShowProductOrders.main(Unknown Source)
Caused by: net.sf.hibernate.PropertyAccessException: Exception occurred inside setter of com.iag.ProductOrder.Customer
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:49)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:216)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2132)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:235)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:128)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:826)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:846)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:420)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2039)
at net.sf.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:1857)
at net.sf.hibernate.proxy.LazyInitializer.initialize(LazyInitializer.java:49)
at net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitializer.java:56)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
... 17 more
Caused by: java.lang.NullPointerException
###

My mapping xml file for the customer table looks like this:

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

<hibernate-mapping>
<class name="com.iag.Customer"
table="customer" lazy="true">

<id name="ID"
type="integer"
column="id"
unsaved-value="-1">
<generator class="assigned"/>
</id>

<version name="modified"
unsaved-value="undefined"/>

<property name="Name"
column="name"
type="string"
not-null="true"
unique="true"/>

<set name="ProductOrder" inverse="true" lazy="true">
<key column="customer_id"/>
<one-to-many class="com.iag.ProductOrder"/>
</set>

</class>
</hibernate-mapping>
###

My mapping for the product_order table looks like this:

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

<hibernate-mapping>
<class name="com.iag.ProductOrder"
table="product_order" lazy="true">

<id name="No"
type="integer"
column="no"
unsaved-value="-1">
<generator class="assigned"/>
</id>

<version name="modified"
unsaved-value="undefined"/>

<property name="ProductCategory"
column="product_category"
type="integer"
not-null="true"/>

<property name="ProductID"
column="product_id"
type="integer"
not-null="true"/>

<property name="Text"
column="text"
type="string"
not-null="false"/>

<many-to-one name="Customer" column="customer_id" not-null="false"/>

</class>
</hibernate-mapping>
###

What can I do to allow null-values in the customer_id column in the product_order table?

Thx for any answers.

Regards,
noips


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 11:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Check ProductOrder.setCustomer(). It is your own code that is throwing the NPE.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 11:54 am 
Newbie

Joined: Wed Dec 03, 2003 11:15 am
Posts: 13
Location: Stuttgart, Germany
gavin wrote:
Check ProductOrder.setCustomer(). It is your own code that is throwing the NPE.


You are right, awkward. Looks like its time to go home.

Thx!

noips


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.