-->
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: persisting booleans in 2.1.2 (and 3) MySQL true=1, false=0
PostPosted: Tue May 11, 2004 1:58 pm 
Newbie

Joined: Tue Aug 26, 2003 1:03 pm
Posts: 2
For some reason, after upgrading to 2.1.2 recently, my application can't seem to persist booleans as true.

This could also be a database issue, but I can't tell what the problem is.

I've been away from following the project for some time so I'm sure the answer is obvious somewhere, but I browsed all last night and could solve it so:

In my hibernate.config.xml I use

Code:
<property name="query.substitutions">true 1, false 0</property>


which is confirmed in my logs:

Code:
12:41:58,666  INFO SettingsFactory:102 - Use scrollable result sets: true
12:41:58,676  INFO SettingsFactory:105 - Use JDBC3 getGeneratedKeys(): false
12:41:58,676  INFO SettingsFactory:108 - Optimize cache for minimal puts: false
12:41:58,676  INFO SettingsFactory:114 - echoing all SQL to stdout
12:41:58,676  INFO SettingsFactory:117 - Query language substitutions: {true=1, false=0}
12:41:58,676  INFO SettingsFactory:128 - cache provider: net.sf.ehcache.hibernate.Provider
12:41:58,696  INFO Configuration:1093 - instantiating and configuring caches
12:41:58,766  INFO SessionFactoryImpl:119 - building session factory



My mapping documents use property="boolean":

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 1.1//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping default-cascade="none">
    <class mutable="true" name="com.rd.Test1" table="test1" proxy="com.rd.Test1" >
    <id column="id" name="id" type="string" unsaved-value="0">
      <generator class="uuid.hex"/>
    </id>
    <property name="foo" type="string" length="30" />
    [b]<property name="foobool" type="boolean" />[/b]
    <many-to-one name="test2" class="com.rd.Test2" />
    </class>
</hibernate-mapping>



Database is MySQL 4.0.18-nt.
For booleans I have been using tinyint(1):

Code:
CREATE TABLE `test1` (
  `id` varchar(32) default '0',
  `foo` varchar(32) default NULL,
  `test2` varchar(32) default NULL,
  `foobool` tinyint(1) default '0'
) TYPE=MyISAM;


Hibernate reads "1" as true -- ie boolean fields set to true before I upgraded (both Hibernate and MySQL) are loaded as true, but they are persisted back as false. So anytime the application persists a boolean field now, it is set to false.

Where should I be looking? Any help greatly appreciated.

John Devine


Top
 Profile  
 
 Post subject: Solution: Upgrade to MySQL Connector/J 3.0
PostPosted: Tue May 11, 2004 4:04 pm 
Newbie

Joined: Tue Aug 26, 2003 1:03 pm
Posts: 2
After upgrading to MySQL connector/j from the org.mm... open source driver, everything seems to be back to normal. Must have been a change in upgrading to MySQL 4 from 3.


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.