-->
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.  [ 2 posts ] 
Author Message
 Post subject: Bug with Hibernate/MySQL/boolean?
PostPosted: Mon Sep 26, 2005 9:48 am 
Beginner
Beginner

Joined: Sun Jul 31, 2005 1:23 pm
Posts: 35
I believe I have found a Hibernate bug. I know that 99% of "bugs" are actually user errors. However...

I get the following exception. Note that the relevant column is set to "NOT NULL"; there are absolutely no NULL values in the database. I get this error both when doing a query and with a record create.

Hibernate: 3.0.5
MySQL: 4.1.13

If anyone could help resolve, I would greatly appreciate it.

Code:
Caused by: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.auenrec.data.Rating.enabled
   at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:59)
   at org.hibernate.tuple.AbstractTuplizer.setPropertyValues(AbstractTuplizer.java:207)
   at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:176)
   at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
   at org.hibernate.loader.Loader.doQuery(Loader.java:436)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
   at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
   at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:643)
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
   at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
   at com.auenrec.data.Rating$$EnhancerByCGLIB$$ade24074.setRatingDate(<generated>)
   at com.auenrec.webbean.ItemRater.doRateItem(Unknown Source)
   at com.auenrec.webbean.ItemRater.getArtificalLoadTrigger(Unknown Source)
   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 com.sun.faces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:79)
   ... 54 more
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:40)
   ... 81 more


Relevant code from Rating.java:
Code:
   // Internal instance variable declaration
   private boolean enabled = true;

   // Accessors
   public boolean getEnabled() { return enabled; }
   public void setEnabled(boolean enabled) { this.enabled = enabled; }


Relevant code from mapping file:
Code:
    <class name="com.auenrec.data.Rating" table="Ratings">
       <composite-id>
         <key-many-to-one name="user" column="UserID"
               class="com.auenrec.data.GenericUser"/>
         <key-many-to-one name="item" column="RatableItemID"
               class="com.auenrec.data.RatableItem"/>
      </composite-id>

        <property name="originalRating" column="OriginalRating" type="float"/>
        <property name="normalizedRating" column="NormalizedRating" type="float"/>
        <property name="ratingDate" column="RatingDate" type="timestamp"/>
        <property name="enabled" column="Enabled" type="boolean"/>
    </class>


MySQL table description:
Code:
+------------------+------------+------+-----+---------+-------+
| Field            | Type       | Null | Key | Default | Extra |
+------------------+------------+------+-----+---------+-------+
| UserID           | int(11)    |      | PRI | 0       |       |
| RatableItemID    | int(11)    |      | PRI | 0       |       |
| OriginalRating   | float      | YES  |     | NULL    |       |
| NormalizedRating | float      | YES  |     | NULL    |       |
| RatingDate       | datetime   | YES  |     | NULL    |       |
| Enabled          | tinyint(1) |      |     | 1       |       |
+------------------+------------+------+-----+---------+-------+


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 12:09 am 
Newbie

Joined: Thu Dec 08, 2005 12:04 am
Posts: 2
Location: Melbourne, Australia
Hey,

I had a simmilar issue, though I am not sure why you would be having this problem with retrieval. Anyway, to make the default value in the database take affect you need to have the dynamic-insert and dynamic-update options set to true in the hibernate mapping for the table. Otherwise the insert query will be constructed using all of the columns, which will mean the default cannot take affect. Also, I have found it helps to use objects rather than primitive types (i.e. Boolean vs boolean).

Hopefuly this helps,

Cheers,

David


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