-->
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.  [ 3 posts ] 
Author Message
 Post subject: Boolean to true_false breaks when upgrading 3.0.5 to 3.2.1ga
PostPosted: Tue Jun 19, 2007 9:13 am 
Newbie

Joined: Mon Jun 18, 2007 6:26 pm
Posts: 3
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?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 9:35 am 
Newbie

Joined: Mon Jun 18, 2007 6:26 pm
Posts: 3
May have solved my own problem...

In my mapping file, I changed:

Code:
<property name="freeInd" column="free_ind" type="true_false"/>


to this:

Code:
<property name="freeInd" type="true_false">
    <column name="free_ind" sql-type="varchar2" length="1" />
</property>



Unit tests passed...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 9:53 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
yeah it looks like you have the right solution. as oracle does not have a boolean type, you will need to use varchar or number with length = 1, depending on if you want to store T/F or 0/1.

Regards,
Jitendra


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.