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