-->
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.  [ 7 posts ] 
Author Message
 Post subject: persisting boolean problem
PostPosted: Thu Jul 01, 2004 12:44 pm 
Newbie

Joined: Thu Feb 26, 2004 7:29 am
Posts: 17
hi all,
I'm having a problem persisting a java.lang.Boolean to a mysql database. Hibernate seems to try to perist this as either 't' or 'f' which mysql ignores.
I'm using mysql 4 and hibernate 2.

The mapping is as follows :

Code:
       
       <property
            name="rpSettable"
            type="java.lang.Boolean"
            update="true"
            insert="true"
            column="rpSettable"
        />


and the relevant log file is :

2004-07-01 16:32:41,092 DEBUG [net.sf.hibernate.type.StringType] binding '111' to parameter: 1
2004-07-01 16:32:41,093 DEBUG [net.sf.hibernate.type.StringType] binding 'MT' to parameter: 2
2004-07-01 16:32:41,093 DEBUG [net.sf.hibernate.type.BooleanType] binding 'true' to parameter: 3
2004-07-01 16:32:41,093 DEBUG [net.sf.hibernate.type.StringType] binding 'ff808081fd7b7bcc00fd7b7d57700002' to parameter: 4
2004-07-01 16:32:41,093 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 5
2004-07-01 16:32:41,093 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 6
2004-07-01 16:32:41,094 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 7
2004-07-01 16:32:41,094 DEBUG [net.sf.hibernate.type.StringType] binding 'ff808081fd7b7bcc00fd7b7e36dd0003' to parameter: 8
2004-07-01 16:32:41,094 DEBUG [net.sf.hibernate.impl.BatcherImpl] Adding to batch
2004-07-01 16:32:41,094 DEBUG [net.sf.hibernate.impl.BatcherImpl] Executing batch size: 1
2004-07-01 16:32:41,125 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
:
:

everything seems to be fine but the sql sent to MySql is :

update hbm_ratecategory set categoryName='111', billType='MO', rpSettable='t',........

mysql ignores the 't' as it is expecting a tinyint. (1 or 0)

not sure if this has anything to do with the 'yes_no' type in hibernate but i want hibernate to just put 1 or 0 in the database.

any ideas or soluitions greatly appreciated.

cheers,
colum.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 12:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
try using type="boolean"


Top
 Profile  
 
 Post subject: re persisting boolean problem
PostPosted: Mon Jul 05, 2004 5:49 am 
Newbie

Joined: Thu Feb 26, 2004 7:29 am
Posts: 17
hi michael,
i've tried setting the type to 'boolean' but this doesn't work either, i still get 't' in the sql that's sent to the database.
i've also upgraded to the latest mysql connector (mysql-connector-java-3.0.14-production-bin.jar) but no joy ;-(

any other ideas?, is this a bug? should i report it?
cheers,
colum.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 05, 2004 12:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I am quite sure type="boolean" uses ints - just look at the source. I am sure you are using a differnet type somewhere.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 05, 2004 12:29 pm 
Newbie

Joined: Thu Feb 26, 2004 7:29 am
Posts: 17
hi michael,
Thanks for your reply. Do you know where else i should look?

My mapping file is :

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="com.yahoo.gmmh.hibernate.RateCategory"
        table="hbm_ratecategory"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.String"
        >
            <generator class="uuid.hex">
            </generator>
        </id>

        <property
            name="rpSettable"
            type="boolean"
            update="true"
            insert="true"
            column="rpSettable"
        />

    </class>

</hibernate-mapping>



and the describe in mysql of the table is :

rpSettable tinyint(1)


i've turned on logging of the sql in mysql and the sql received definitly contains 't' instead of '1'.

not sure where else i need to check???

thanks,
colum.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 05, 2004 12:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are mistaken.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 06, 2004 7:05 am 
Newbie

Joined: Thu Feb 26, 2004 7:29 am
Posts: 17
hi gavin,
i don't doubt that i'm mistaken but have no idea where???? ;-(

i'm using the latest hibernate (2.1.4) and mysql (4.0.15)

my java code is as follows :

**snip **
Code:

  private boolean rpSettable = false;

  public boolean isRpSettable() {
    return this.rpSettable;
  }
  public void setRpSettable(boolean rpSettable) {
     this.rpSettable = rpSettable;
  }

i've also tried using java.lang.Boolean for the type.

i'm using xdoclet to generate the hibernate mapping file and it produces :

Code:
        <property
            name="rpSettable"
            type="boolean"
            update="true"
            insert="true"
            column="rpSettable"
        />


with hibernate logging turned on i get :

Code:

2004-07-06 10:38:16,462 INFO  [STDOUT] Hibernate: insert into hbm_ratecategory (categoryName, billType, rpSettable, operatorID, currencyRateID, creditRateID, replyPathID, id) values (?, ?, ?, ?, ?, ?, ?, ?)
2004-07-06 10:38:16,466 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2004-07-06 10:38:16,466 DEBUG [net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.yahoo.gmmh.hibernate.RateCategory#ff808081fd9404d200fd9408478b0003]
2004-07-06 10:38:16,466 DEBUG [net.sf.hibernate.type.StringType] binding '40' to parameter: 1
2004-07-06 10:38:16,466 DEBUG [net.sf.hibernate.type.StringType] binding 'MT' to parameter: 2
2004-07-06 10:38:16,466 DEBUG [net.sf.hibernate.type.BooleanType] binding 'true' to parameter: 3
2004-07-06 10:38:16,467 DEBUG [net.sf.hibernate.type.StringType] binding 'ff808081fd9404d200fd9407db960002' to parameter: 4
2004-07-06 10:38:16,467 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 5
2004-07-06 10:38:16,467 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 6
2004-07-06 10:38:16,467 DEBUG [net.sf.hibernate.type.StringType] binding null to parameter: 7
2004-07-06 10:38:16,467 DEBUG [net.sf.hibernate.type.StringType] binding 'ff808081fd9404d200fd9408478b0003' to parameter: 8
2004-07-06 10:38:16,467 DEBUG [net.sf.hibernate.impl.BatcherImpl] Adding to batch
2004-07-06 10:38:16,467 DEBUG [net.sf.hibernate.impl.BatcherImpl] Executing batch size: 1
2004-07-06 10:38:16,539 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2004-07-06 10:38:16,539 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement


parameter 3 is the problem one, is the mapping correct here???
it all looks ok to me as i'm expecting a 'true' but it seems to go wrong from here on.

i've turned on logging in mysql to see the sql that it receives and it gets :

Code:
insert into hbm_ratecategory (categoryName, billType, rpSettable, operatorID, currencyRateID, creditRateID, replyPathID, id) values ('40', 'MT', 't', 'ff808081fd9404d200fd9407db960002', null, null, null, 'ff808081fd9404d200fd9408478b0003')


as you can see the 't' is the problem. ;-(
the definition of the table in mysql has a tinyint(1) for the column 'rpSettable'.

if you can see where i'm going wrong i'd greatly appreciate some help.

cheers,
colum.


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