-->
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: Reading NULL in a double property
PostPosted: Sun Nov 14, 2004 6:21 am 
Newbie

Joined: Thu May 20, 2004 7:39 am
Posts: 12
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

_________________
Dmitri Pissarenko
Software Engineer
http://dapissarenko.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 14, 2004 6:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Either use Double not double or use a UserType that converts NULL to something else.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 14, 2004 10:40 am 
Newbie

Joined: Thu May 20, 2004 7:39 am
Posts: 12
Thanks!

_________________
Dmitri Pissarenko
Software Engineer
http://dapissarenko.com


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.