-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate creates bit instead of boolean
PostPosted: Sat Jan 01, 2005 12:51 pm 
Beginner
Beginner

Joined: Sat Jan 01, 2005 12:18 pm
Posts: 23
I'm new to hibernate and I have got a problem with mapping (actually creating) a boolean class attribute to a boolean database attribute.

Class Attribute looks like:

Code:
private boolean isAdmin;


corrsponding mapping property is:

Code:
<property name="isAdmin"  column="isAdmin" not-null="false"/>


Hibernate creates this attribute as a "bit" type in my Postgres database and so I get an error message if I want to set the value to false or true.

I already tried to set
Code:
type="boolean"
but it still creates a bit type.

Any ideas howto create a bool type?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 01, 2005 4:47 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
1) What version of Hibernate are you using?
2) Why do you name your property isAdmin? Name it admin and provide an appropriate getter and setter - javabean style:

Code:

private boolean admin;

public boolean isAdmin() {
    return admin;
}

public void setAdmin(boolean b) {
    admin = b;
}


3) Your mapping should look something like:

Code:
<property
            name="admin"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="isAdmin"
            not-null="true"
        />


4) Please post you hibernate.cfg.xml file if the problem persists


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 02, 2005 8:50 am 
Beginner
Beginner

Joined: Sat Jan 01, 2005 12:18 pm
Posts: 23
1.) Im using Hibernate 2.1.7
2.) Why not naming it like that? However ... I have getters and setters for that attribute

3.) mapping looks the same except the optional settings

4.) Im using Spring

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>org.postgresql.Driver</value></property>
<property name="url"><value>jdbc:postgresql://centrino/testapp</value></property>
<property name="username"><value>admin</value></property>
<property name="password"><value>xxx</value></property>
</bean>

<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<list>
<value>testapp/model/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 02, 2005 9:12 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Why are you using HSQL dialect with Postgres?

Your dialect in your config file should be:

Code:
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.