Hello!
I have a database table with a field called H_Waste.
This table should be mapped to a class, which has a property hazardousWaste (with getter and setter, of course).
The XML descriptor looks as shown below.
Code:
<?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 package="grEEEn.grEEEn2demetrix.grEEEnModel">
<class name="GrEEEnProcess"
table="tbl_process"
discriminator-value="N">
<id name="id" column="ID_process">
<generator class="native"/>
</id>
<property name="hazardousWaste" column="H_waste" not-null="true"/>
</class>
</hibernate-mapping>
In most cases, everything works fine.
However, in some very few rows of the table, H_Waste is equal to NULL (no 0.0, but NULL).
If H_Waste is equal to NULL, I'm getting this exception
Code:
ERROR
net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of grEEEn.grEEEn2demetrix.grEEEnModel.GrEEEnProcess.setNonHazardousWaste
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:212)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2199)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:240)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at net.sf.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:541)
at test.grEEEn.grEEEn2demetrix.grEEEnModel.GrEEEnProcessTest.testReadingOfCed(GrEEEnProcessTest.java:302)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: net.sf.cglib.beans.BulkBeanException
at grEEEn.grEEEn2demetrix.grEEEnModel.GrEEEnProcess$$BulkBeanByCGLIB$$56651ee9.setPropertyValues(<generated>)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:207)
... 23 more
Caused by: java.lang.NullPointerException
... 25 more
One solution is to set H_waste to 0.0 in all rows, where it is equal to NULL.
Is there any other solution?
Thanks in advance
dap