-->
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.  [ 5 posts ] 
Author Message
 Post subject: IllegalArgumentException in Boolean set [SOLVED]
PostPosted: Fri Dec 08, 2006 12:20 pm 
Newbie

Joined: Fri Dec 08, 2006 11:48 am
Posts: 6
Hibernate version: 3.2.1
Name and version of the database you are using: HSQLDB 1.8.0.7

I'm a hibernate newbie and after setting everything up in the mapping document and reading the documentation, I start a session with

Code:

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List sdList = session.createQuery("from SystemDetails as sd where
    sd.description = ?").setString(0, databaseName).list();
if (sdList.size() > 0)
   return (SystemDetails)sdList.get(0);


SystemDetails is a big object that has cascade=save-update all the way down the tree. Initially this executes fine as everything lazy loads by default. But when using the application to load up a particular dialog, I get this error on the save object and same field EVERY time:

Code:
Exception in thread "AWT-EventQueue-0" org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of babboo.xclone.datamodel.change_text.ChangeRuleList.defaultList
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:85)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
   at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
   at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3514)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
   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:224)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
   at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentList.hashCode(PersistentList.java:467)
   at babboo.xclone.datamodel.change_text.ChangeRuleList.hashCode(ChangeRuleList.java:89)
   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:585)
   at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:147)
   at babboo.xclone.datamodel.change_text.ChangeRuleList$$EnhancerByCGLIB$$a4ab39e7.hashCode(<generated>)
   at babboo.xclone.datamodel.ConfigFile.hashCode(ConfigFile.java:107)
   at java.util.HashMap.hash(HashMap.java:264)
   at java.util.HashMap.containsKey(HashMap.java:342)
   at java.util.HashSet.contains(HashSet.java:182)
   at babboo.xclone.ace.dialog.RuntimeConfigurationDialog.createAllView(RuntimeConfigurationDialog.java:275)
   at babboo.xclone.ace.dialog.RuntimeConfigurationDialog.setupTree(RuntimeConfigurationDialog.java:918)
   at babboo.xclone.ace.dialog.RuntimeConfigurationDialog.init(RuntimeConfigurationDialog.java:263)
   at babboo.xclone.ace.dialog.RuntimeConfigurationDialog.<init>(RuntimeConfigurationDialog.java:53)
   at babboo.xclone.ace.Ace$ToolsRuntimeConfigAction.actionPerformed(Ace.java:4959)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
   at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
   at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
   at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
   at java.awt.Component.processMouseEvent(Component.java:5488)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
   at java.awt.Component.processEvent(Component.java:5253)
   at java.awt.Container.processEvent(Container.java:1966)
   at java.awt.Component.dispatchEventImpl(Component.java:3955)
   at java.awt.Container.dispatchEventImpl(Container.java:2024)
   at java.awt.Component.dispatchEvent(Component.java:3803)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
   at java.awt.Container.dispatchEventImpl(Container.java:2010)
   at java.awt.Window.dispatchEventImpl(Window.java:1774)
   at java.awt.Component.dispatchEvent(Component.java:3803)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.lang.IllegalArgumentException
   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:585)
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
   ... 57 more


Here's an excerpt from the mapping file:
Code:
<!-- ChangeRuleList -->
<union-subclass
    name="ChangeRuleList"
        table="XCL_CHANGE_RULE_LIST">
    <property name="name" access="field"/>
    <property name="defaultList" column="DEFAULT_LIST" type="boolean"/>
    <list name="changeRules" table="XCL_RULE_LIST_ELEMENTS">
        <key column="RULE_LIST"/>
   <list-index column="SORT_ORDER"/>
   <many-to-many column="CHANGE_RULE" 
        class="ChangeRule"/>
    </list>
</union-subclass>


The field in question is defaultList and I can see that hibernate is trying to set this boolean field with null. I've debugged the code and can see that it thinks the field type is Boolean, so I wonder what's causing the problem? Any ideas?


Last edited by markbarrett on Sat Dec 09, 2006 8:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 12:39 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Is your column nullable in the database? If so, Hibernate is probably trying to load a record with a null value and can't translate that to a boolean field in your class. My guess is that your member variable is of type boolean and needs to be Boolean to handle the null value.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 1:02 pm 
Newbie

Joined: Fri Dec 08, 2006 11:48 am
Posts: 6
Nathan: All the values in this column are set to 'true' or 'false' and never null. I've also tried setting my mapping to say 'not-null="true"', and recreating the DB, but this didn't fix the problem.

This is a real show stopper for me if I can't get around it. On debugging, I can see a structure called hydratedState which is an Object[]. This contains the values of the object shortly before they're set, but the Type.Boolean is set to null and another field of Type.String is set to null too, yet I don't have any null Strings in the DB. A long query runs shortly before this point, but no results are returned.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 2:03 pm 
Newbie

Joined: Fri Dec 08, 2006 11:48 am
Posts: 6
Okay, I was wrong about the query returning no results. It returns all rows for the collection. But the Boolean and String fields I'm interested in that are returned in the query are null

Code:
select changerule0_.RULE_LIST as RULE1_1_,
   changerule0_.CHANGE_RULE as CHANGE2_1_,
   changerule0_.SORT_ORDER as SORT3_1_,
   changerule1_.ID as ID0_0_,
   changerule1_.version as version0_0_,
   changerule1_.CHANGE_RESTRICTION_LIST as CHANGE1_53_0_,
   changerule1_.name as name54_0_,
   changerule1_.DEFAULT_LIST as DEFAULT2_54_0_,
   changerule1_.REPLACE_STRING as REPLACE1_56_0_,
   changerule1_.SEARCH_STRING as SEARCH2_56_0_,
   changerule1_.SEARCH_STRING as SEARCH1_59_0_,
   changerule1_.REPLACE_STRING as REPLACE2_59_0_,
   changerule1_.clazz_ as clazz_0_
from XCL_RULE_LIST_ELEMENTS changerule0_
left outer join ( select
   null as DEFAULT_LIST,
   null as REPLACE_STRING,
   CHANGE_RESTRICTION_LIST,
   null as name,
   null as SEARCH_STRING,
   ID,
   version,
   23 as clazz_
from XCL_CHANGE_RULE
union select
   DEFAULT_LIST,
   null as REPLACE_STRING,
   CHANGE_RESTRICTION_LIST,
   name,
   null as SEARCH_STRING,
   ID,
   version,
   24 as clazz_
from XCL_CHANGE_RULE_LIST
union select
   null as DEFAULT_LIST,
   REPLACE_STRING,
   CHANGE_RESTRICTION_LIST,
   null as name,
   SEARCH_STRING,
   ID,
   version,
   25 as clazz_
from XCL_REPLACE_REG_EXP_RULE
union select null
   as DEFAULT_LIST, REPLACE_STRING, CHANGE_RESTRICTION_LIST, null
   as name, SEARCH_STRING, ID, version, 26
   as clazz_
from XCL_REPLACE_STRING_RULE ) changerule1_ on changerule0_.CHANGE_RULE=changerule1_.ID
where changerule0_.RULE_LIST=13019;


In the first union I can see "null as DEFAULT_LIST" and "null as name" which seem to be causing the problem. If I remove this first union (it's an empty table anyway), I get the values I want when I run the query.

I don't know how unions work in this SQL. I know columns have to be of the same type, but shouldn't the named column without the "null as" override the "null as" column earlier declared?

I'm hoping there's someone who understands SQL here and who can understand my explanation. Hopefully I'm not barking up the wrong tree!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 8:30 am 
Newbie

Joined: Fri Dec 08, 2006 11:48 am
Posts: 6
I've discovered the problem. It's to do with the query hibernate runs on HSQLDB. There's a bug in this version of HSQLDB in that some columns on union inner selects return null.

A simple test:

Code:
CREATE TABLE t1 (a integer)
CREATE TABLE t2 (b integer)
INSERT INTO t2 VALUES (1);

then

SELECT alias.a, alias.b
from (
        select a, null as b
        from t1 union
        select null as a, b
        from t2
    ) alias;

produces

| NULL | NULL |

when it should produce

| NULL | 1 |


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