Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange Hibernate exception with column type
    primarykey
    data
    text
    <p>I am getting Hibernate exception: </p> <blockquote> <p>Wrong column type. Found: bit, expected: BOOLEAN DEFAULT TRUE</p> </blockquote> <p>I have class User:</p> <pre><code>package mypackage; import javax.persistence.*; import java.util.ArrayList; import java.util.List; @Entity @Table(name = "USER") public class User { @Id @GeneratedValue @Column(name = "ID", unique = true, nullable = false) private Long id; @Column(name = "STATUS", columnDefinition = "BOOLEAN DEFAULT TRUE", nullable = false) private Boolean status = Boolean.TRUE; // getters and setters } </code></pre> <p>This works properly if Hibernate creates table itself in database. When </p> <pre><code>&lt;property name="hibernate.hbm2ddl.auto"&gt;create&lt;/property&gt; </code></pre> <p>or </p> <pre><code>&lt;property name="hibernate.hbm2ddl.auto"&gt;create-drop&lt;/property&gt; </code></pre> <p><strong>But if</strong></p> <ol> <li>I run my program and allow Hibernate to create this table </li> <li>then I change the value of <code>hibernate.hbm2ddl.auto</code> to the <strong>validate</strong> </li> <li><p>and I run my program again with the table that has generated by Hibernate and with</p> <pre><code>&lt;property name="hibernate.hbm2ddl.auto"&gt;validate&lt;/property&gt; </code></pre></li> </ol> <p>so I get the exception: </p> <blockquote> <p><strong>org.hibernate.HibernateException: Wrong column type in dbtest.user for column STATUS. Found: bit, expected: BOOLEAN DEFAULT TRUE</strong></p> </blockquote> <p>Any idea what could be the reason for this behavior of Hibernate and how can I fix it?</p> <p>I use <code>MySQL server 5.1</code> and <code>Hibernate 4.0.1</code>. </p> <p>My <code>Run</code> class is just two lines:</p> <pre><code> public class Run { public static void main(String[] main) { SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); Session session = sessionFactory.getCurrentSession(); } } </code></pre> <p>The structure of the table:</p> <pre><code>CREATE TABLE USER ( ID BIGINT(20) NOT NULL AUTO_INCREMENT, STATUS TINYINT(1) NOT NULL DEFAULT 1, PRIMARY KEY (ID), UNIQUE INDEX ID (ID) ) COLLATE='utf8_general_ci' ENGINE=MyISAM ROW_FORMAT=DEFAULT AUTO_INCREMENT=2 </code></pre> <p>My <code>hibernate.cfg</code>:</p> <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt; &lt;property name="connection.url"&gt;jdbc:mysql://127.0.0.1:3306/dbtest&lt;/property&gt; &lt;property name="connection.username"&gt;root&lt;/property&gt; &lt;property name="connection.password"&gt;root&lt;/property&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt; &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt; &lt;property name="connection.pool_size"&gt;5&lt;/property&gt; &lt;property name="hibernate.transaction.flush_before_completion"&gt;true&lt;/property&gt; &lt;property name="hibernate.transaction.auto_close_session"&gt;true&lt;/property&gt; &lt;property name="hibernate.hbm2ddl.auto"&gt;validate&lt;/property&gt; &lt;property name="hibernate.show_sql"&gt;false&lt;/property&gt; &lt;property name="hibernate.format_sql"&gt;true&lt;/property&gt; &lt;property name="hibernate.use_sql_comments"&gt;false&lt;/property&gt; &lt;property name="hibernate.connection.charSet"&gt;true&lt;/property&gt; &lt;mapping class="mypackage.User"/&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <p>Hibernate creates the table with type <code>TINYINT</code> and I do not intermeddle on to the database and do not make any changes in the table manually! I'm just change the <code>hibernate.hbm2ddl.auto</code> to the <code>validate</code> and nothing else.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload