-->
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.  [ 5 posts ] 
Author Message
 Post subject: Java Class Generation with schema for DB2 mismatch
PostPosted: Tue Apr 12, 2005 2:45 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Hi,

I am using the latest Artifact Extractor in Eclispe 3.1M5 to build the Hibernate XML mapping (hbm.xml) and the java Pojo classes. For testing purpose, I am doing the extraction on a MySQL database. And I have this strange issue, the java Pojo set most field like java.lang.Character, but it should be set as String. It seems that all DB table column set as Char(##) are transpose as a java.lang.Character in the Pojo... Is that a Bug?

Here the database ddl:
Code:
create table GNDIVI00 (
     DIDIVI               CHAR(6)                        default ' ' not null,
     DINOM                CHAR(40)                       default ' ' not null,
     DIUSAR               CHAR(10)                       default ' ' not null,
     DIREST               CHAR(1)                        default ' ' not null,
     DIDATC               NUMERIC(8)                     default 0 not null,
     DIHRSC               NUMERIC(4)                     default 0 not null,
     DIUSAC               CHAR(10)                       default ' ' not null,
     DIDATM               NUMERIC(8)                     default 0 not null,
     DIHRSM               NUMERIC(4)                     default 0 not null,
     DIUSAM               CHAR(10)                       default ' ' not null,
     constraint PK_GNDIVI00 primary key (DIDIVI)
)


here the the Pojo:
Code:

// default package


/**
* Gndivi00 generated by hbm2java
*/
public class Gndivi00  implements java.io.Serializable {

    // Fields   

    private java.lang.Character Didivi;
    private java.lang.Character Dinom;
    private java.lang.Character Diusar;
    private java.lang.Character Direst;
    private java.math.BigDecimal Didatc;
    private java.math.BigDecimal Dihrsc;
    private java.lang.Character Diusac;
    private java.math.BigDecimal Didatm;
    private java.math.BigDecimal Dihrsm;
    private java.lang.Character Diusam;


    // Constructors

    /** default constructor */
    public Gndivi00() {
    }
   
    /** constructor with id */
    public Gndivi00(java.lang.Character Didivi) {
        this.Didivi = Didivi;
    }
   
   

    // Property accessors
    /**
     */
   public java.lang.Character getDidivi () {
        return this.Didivi;
    }
   
   public void setDidivi (java.lang.Character Didivi) {
        this.Didivi = Didivi;
    }
    /**
     */
   public java.lang.Character getDinom () {
        return this.Dinom;
    }
   
   public void setDinom (java.lang.Character Dinom) {
        this.Dinom = Dinom;
    }

etc...


and here'es the hbm.xml:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<!--
   Auto-generated mapping file from
   the hibernate.org cfg2hbm engine
-->
<class
    name="Gndivi00"
    table="gndivi00"
    catalog=""
>
   <id
        name="Didivi"
        type="java.lang.Character"
    >
       <column name="DIDIVI" length="6" not-null="true" sql-type="char" />
       <generator class="assigned" />
    </id>
   
    <property
        name="Dinom"
        type="java.lang.Character"
    >
        <column name="DINOM" length="40" not-null="true" sql-type="char" />
   </property>

    <property
        name="Diusar"
        type="java.lang.Character"
    >
        <column name="DIUSAR" length="10" not-null="true" sql-type="char" />
   </property>

    <property
        name="Direst"
        type="java.lang.Character"
    >
        <column name="DIREST" length="1" not-null="true" sql-type="char" />
   </property>

    <property
        name="Didatc"
        type="java.math.BigDecimal"
    >
        <column name="DIDATC" length="8" not-null="true" sql-type="decimal" />
   </property>

    <property
        name="Dihrsc"
        type="java.math.BigDecimal"
    >
        <column name="DIHRSC" length="4" not-null="true" sql-type="decimal" />
   </property>

    <property
        name="Diusac"
        type="java.lang.Character"
    >
        <column name="DIUSAC" length="10" not-null="true" sql-type="char" />
   </property>

    <property
        name="Didatm"
        type="java.math.BigDecimal"
    >
        <column name="DIDATM" length="8" not-null="true" sql-type="decimal" />
   </property>

    <property
        name="Dihrsm"
        type="java.math.BigDecimal"
    >
        <column name="DIHRSM" length="4" not-null="true" sql-type="decimal" />
   </property>

    <property
        name="Diusam"
        type="java.lang.Character"
    >
        <column name="DIUSAM" length="10" not-null="true" sql-type="char" />
   </property>

</class>
</hibernate-mapping>


Sorry if I didn't test it; but at first glance, when a method return a "java.lang.Character" it only return 1 character, not 8 or 40...
Any idea? Is it supposed to works ?

Thanks

Etienne
Montreal.


Top
 Profile  
 
 Post subject: Char(20) create a java.lang.Character instead of String
PostPosted: Tue Apr 12, 2005 2:50 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Sorry for the title.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 4:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
seems we need to get started on the "test all weird combinations of type constructs that is possible on dbs and which are not consistent with spec" unit test ,)

if you could provide a simple test case and put it in jira it would be great.

thank you

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 5:01 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Sure, if I know how...

I could provide a TestCase, but I dont see how you could/should test it. Do you need to previously import a kind of DDL (create a DB? a db mock object?) and then do the "Artifact Generation", and then do the test case on the generated pojo?

I think I found Another "bug". The MySQL type binary(1) is translate to a java.lang.Object (in the hbm.xml and in the java Pojo class). I think it should be a Boolean or a bool (if Hibernate allows primitive type, I dont remerber now).

The mapping with java.lang.Object doesn't works when I am doing the "connection Factory" in the Hibernate Console. Some problem with the column... So, I change the field in the pojo for a Boolean and I remove the "type=java.lang.Object" in the hbm.xml to allow the Hibernate reflection. And then it works well.

Etienne
Montreal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 1:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
create the DDL that has the "bad" types. attach it

create a hbm.xml via the rev.eng. attach it

adjust the hbm.xml to have the expected types. attach it.

write down the db and driver version you used. attach that text.

voila - you've done what i've needed ,)

-max

_________________
Max
Don't forget to rate


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