-->
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.  [ 11 posts ] 
Author Message
 Post subject: Reverse Engineering database with Eclipse plugin
PostPosted: Wed Jun 22, 2005 9:49 pm 
Newbie

Joined: Wed Jun 22, 2005 3:58 am
Posts: 14
I tried to use the reverse engineering feature of the Eclipse plugin and I have a question about a certain peculiarity I noticed.

The mapping files were generated very well. For example:

Mapping documents:

Code:
<hibernate-mapping>
<!--
        Auto-generated mapping file from
        the hibernate.org cfg2hbm engine
-->
  <class name="com.allcorp.premium.coverage.data.orm.classes.XatAutoCovrg" table="XAT_AUTO_COVRG" schema="ALLIDB" catalog="R0234376" lazy="false">
    <composite-id name="id" class="com.allcorp.premium.coverage.data.orm.classes.XatAutoCovrgId">
      <key-property name="AcvProduct" type="java.lang.Character">
        <column name="ACV_PRODUCT" scale="8" precision="0" not-null="true" sql-type="CHAR" />
      </key-property>
... etc


So, we have a column declared as CHAR(8) in the database.

Here is the code generated for this mapping:

Code:
package com.allcorp.premium.coverage.data.orm.classes;


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

    // Fields   

private java.lang.Character AcvProduct;
private java.lang.Character AcvProductType;
private java.lang.Character AcvVehicleType;
private java.lang.Short AcvVersion;

... etc


Notice how the java type chosen for the CHAR(8) column is a java.lang.Character, which only takes 1 character instead of 8.

Why is hbm2java doing it this way?

Hibernate version: 3.0.5


Top
 Profile  
 
 Post subject: Character fields
PostPosted: Thu Jun 23, 2005 1:33 pm 
Newbie

Joined: Thu Jun 23, 2005 1:23 pm
Posts: 3
I have the same issue here. I think that you can customize this with the reveng.xml file. See topic "3.2 hibernate.reveng.xml file" at http://www.hibernate.org/hib_docs/tools/ant/index.html

[]'s
Bruno


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 3:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we should be able to provide i better default I agree.

submit a jira for it.
until then use reveng.xml to work around it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 9:49 pm 
Newbie

Joined: Wed Jun 22, 2005 3:58 am
Posts: 14
Is there a way to make the Eclipse Reverse Engineer plugin use the hibernate.reveng.xml file?

I know it can be specified with revengfile attribute of the <jdbcconfiguration> task, but I don't see anything in the plugin.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 1:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
there is overrivde xml field in the artifact generation

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 2:54 pm 
Newbie

Joined: Wed Jun 22, 2005 3:58 am
Posts: 14
ok, I upgraded to hibernate-tools-3.0.0.alpha4a and used the "Override XML" field to point to my hibernate.reveng.xml file.

The file looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
   <type-mapping>
      <sql-type jdbc-type="CHAR" hibernate-type="string" />
   </type-mapping>
</hibernate-reverse-engineering>


I would expect this to result in all CHAR fields being mapped to strings, but they are still being mapped like this:
Code:
        <property name="acvPipCd" type="character">
            <column name="ACV_PIP_CD" length="1" not-null="true" />
        </property>


What am I still missing?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 3:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - it should work.

are you sure that the return type from the database actually is a javax.sql.Types.CHAR ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 5:46 pm 
Newbie

Joined: Wed Jun 22, 2005 3:58 am
Posts: 14
How would I find out if Hibernate tools interpret the CHAR column in the db as javax.sql.Types.CHAR?

The database type is definately CHAR:

Code:
select COLUMN_NAME, DATA_TYPE, LENGTH from SYSCOLUMNS where table_name='XAT_AUTO_COVRG' and COLUMN_NAME='ACV_PIP_CD' ;

COLUMN_NAME          DATA_TYPE      LENGTH     
-------------------- --------- -----------
ACV_PIP_CD           CHAR                1

  1 record(s) selected.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 1:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
put a log4j.properties in the classpath of the tools (easiest with ant - in eclipse you would need to add it to one of its jars)

then see in the debug log how it interpret the column

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 5:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
just verified this...

in the current version you need to specify either length, precision or scale.

so this should work for your case:

Code:
<sql-type jdbc-type="CHAR" length='1' hibernate-type="string" />

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 5:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
btw.

reported, fixed and committed

http://opensource.atlassian.com/project ... se/HBX-318

_________________
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.  [ 11 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.