My database stores boolean values as 'T' or 'F' in a VARCHAR2 field.
Using Hibernate 3.0.5 I was able to map a boolean in my class to a VARCHAR2(1) in my Oracle 10 DB by using this simple line in the class mapping file:
Code:
<property name="freeInd" column="free_ind" type="true_false"/>
However, when I upgraded to Hibernate 3.2.1.ga, this mapping stopped functioning. I am receiving the following errors during unit testing:
Code:
Initial SessionFactory creation failed.org.hibernate.HibernateException: Wrong column type: free_ind, expected: char(1)
...
java.lang.ExceptionInInitializerError
at com.turner.playon.util.HibernateUtil.<clinit>(HibernateUtil.java:17)
at com.turner.playon.test.TestHibernate.setUp(TestHibernate.java:43)
at junit.framework.TestCase.runBare(TestCase.java:128)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.HibernateException: Wrong column type: free_ind, expected: char(1)
at org.hibernate.mapping.Table.validateColumns(Table.java:261)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1080)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
at com.turner.playon.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 15 more
Everything I have read on these forums suggests that the type="true_false" indicator should work. However, I'm not quite sure how to tell Hibernate not to expect the CHAR(1) column type.
I eventually broke down and began writing my own custom user type, but surely this is an overly complicated answer to a simple question.
Hibernate: 3.2.1.ga
Oracle JDBC driver: ojdbc14-10.2.0.2.0
Code:
<hibernate-configuration>
<session-factory>
<!-- Database Connection Settings -->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@sbbp1devdb1:1530:sbbd1</property>
<property name="hibernate.connection.username">*****</property>
<property name="hibernate.connection.password">*****</property>
<property name="hibernate.default_schema">BBS_OWNER</property>
<!-- JDBC connection pool -->
<property name="connection.pool_size">0</property>
<!-- SQL Dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Set second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Debug: Echo all SQL statements to stdout -->
<property name="hibernate.show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hibernate.hbm2ddl.auto">validate</property>
<!-- Hibernate Class Mapping Resources -->
<mapping resource="com/turner/playon/model/Event.hbm.xml" />
</session-factory>
</hibernate-configuration>
Any suggestions?