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.  [ 8 posts ] 
Author Message
 Post subject: [Hibernate Tools] Unknown types and others problems
PostPosted: Wed Jan 02, 2008 12:21 pm 
Newbie

Joined: Wed Jan 02, 2008 11:17 am
Posts: 6
Hello Everobody.

First of all I would like to apologize for my poor English, I'm French and I Think you're going to realize it.

I'm discovering Hibernate since a few days, and there are some problems I can not solve.

I'm trying to do "reverse engineering" with hibernate-tools and I've got the following problems :

- I'm using an Oracle database and it seems that "varchar2" type (and others) are unknown.
I've tried to deal by overriding "JDBCToHibernateTypeHelper" and "java.sql.Types" classes, but I think there is another class to override (the one where "JDBCToHibernateTypeHelper" is called I think), and how to specify in the cfg file that it must be used instead of the default one.

In reality I don't know if it is the good method.
With "Middlegen" I was using "JavaTypeMapper" property, does the same thing exist in "hibernate-tools"?

I also (still in Middlegen) overrided "MySQL2Java" class where I could specify some new types, can I do the same with "hibernate-tools"?

- I'm also in trouble with decimal numbers.
In the database, I've got the following definition :
Quote:
ARTPMTP number(19,2)

And here is what I get in the mapping file :
Quote:
<property name="artpmtp" type="java.lang.Double">
<column name="ARTPMTP" precision="126" scale="0" />
</property>

What's going on? Is the jdbc driver going crazy?

- Another little question:
In the database, some comment are associated with fields and tables, can I get them automatically to have something like this in the mapping file ?
Quote:
<hibernate-mapping package="default.connection.art">
<class name="Art" table="ART">

<meta attribute="class-description"><![CDATA[Fichier stock article F-ART ]]></meta>
...
<property name="ARTENT" column="ARTENT" type="string" length="1">
<meta attribute="field-description"><![CDATA[Entreprise ]]></meta>
</property>
...


- At last, and least :
I,'ve ssen something like that in some exmaples :
Quote:
<hibernate-mapping package="default.connection.art">
<class name="Art" table="ART">


But I have something like this:
Quote:
<hibernate-mapping>
<class name="default.connection.art.Art" table="ART">

Is there a way to congigure hibernate-tools to get the first example?

I Thank you for having read me, and I hope someone will save me.
Bye


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 12:53 pm 
Newbie

Joined: Wed Jan 02, 2008 11:17 am
Posts: 6
For the last 2 points I think templates will be OK, but I don't know how to use templates so, I think I'll be back :-)
...
Edit :
Here it, is, I'm Back
I don't understand which template I must modify.
I've modified "hibernate-mapping.hbm.ftl" and other (persistenclass.hbm.ftl etc) and moved it in a special repository wich I specify in Eclipse configuration window, but...nothing appends.
I assume that the "${clazz.table.comment}" should dispaly table comments but I have not any result so if you could help me...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 5:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
99% of these questions are answered in the docs ... could you read those and come back with the ones you did not found answered ?

The 1% is about the packages generation; then for now hibernate tools doesn't generate the package statement in hbm.xml, but I guess it could actually be done pretty easiliy. Put a feature request into hibernate jira.

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 4:36 am 
Newbie

Joined: Wed Jan 02, 2008 11:17 am
Posts: 6
I'm sorry but I've already read the docs here : http://www.hibernate.org/hib_docs/tools/reference/en/html_single/#d0e1137 and did not find answers for those questions, maybe I'm too bad at English or I did not read the latest docs but you know, if I asked those questions it's because I've not found the answers in those docs (for example for the unknonw types).


Top
 Profile  
 
 Post subject: Re: [Hibernate Tools] Unknown types and others problems
PostPosted: Thu Jan 03, 2008 4:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
youlhann wrote:
I'm discovering Hibernate since a few days, and there are some problems I can not solve.


If you are new with hibernate I would recommend going through the hibernate tutorials by hand instead of using reverse engineering upfront.
Just a small advice ;)


Quote:
- I'm using an Oracle database and it seems that "varchar2" type (and others) are unknown.
I've tried to deal by overriding "JDBCToHibernateTypeHelper" and "java.sql.Types" classes, but I think there is another class to override (the one where "JDBCToHibernateTypeHelper" is called I think), and how to specify in the cfg file that it must be used instead of the default one.


Overriding JDBCToHibernateTypeHelper is wrong ;)

If you want programmatic control add a custom ReverseEngineeringStrategy. Look it up in the docs.

Quote:
In reality I don't know if it is the good method.
With "Middlegen" I was using "JavaTypeMapper" property, does the same thing exist in "hibernate-tools"?


yes, see the docs about type-mapping.

Quote:
- I'm also in trouble with decimal numbers.
In the database, I've got the following definition :
Quote:
ARTPMTP number(19,2)

And here is what I get in the mapping file :
Quote:
<property name="artpmtp" type="java.lang.Double">
<column name="ARTPMTP" precision="126" scale="0" />
</property>

What's going on? Is the jdbc driver going crazy?


Probably since we only spits out what the driver is telling us (or rather what the MetaDataDialect class tells us which by default is based on jdbc metadata and for others, like oracle and mysql is (partially) based on native metadata inforomation)

Quote:
- Another little question:
In the database, some comment are associated with fields and tables, can I get them automatically to have something like this in the mapping file ?
Quote:
<hibernate-mapping package="default.connection.art">
<class name="Art" table="ART">

<meta attribute="class-description"><![CDATA[Fichier stock article F-ART ]]></meta>
...
<property name="ARTENT" column="ARTENT" type="string" length="1">
<meta attribute="field-description"><![CDATA[Entreprise ]]></meta>
</property>
...



We don't do that by default but you can customize the *.hbm.ftl templates to include it. See docs with an example on how to do this.

Quote:
- At last, and least :
I,'ve ssen something like that in some exmaples :
Quote:
<hibernate-mapping package="default.connection.art">
<class name="Art" table="ART">


But I have something like this:
Quote:
<hibernate-mapping>
<class name="default.connection.art.Art" table="ART">

Is there a way to congigure hibernate-tools to get the first example?


Yes it is possible, just not done yet. Add to jira.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 5:15 am 
Newbie

Joined: Wed Jan 02, 2008 11:17 am
Posts: 6
Ok I'll try to solve all this, thank you very much Max :-)

But I'm sorry, but I think not all is in the docs, well, doesn't matter, I'll try to look for it harder in the docs.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 04, 2008 12:14 pm 
Newbie

Joined: Wed Jan 02, 2008 11:17 am
Posts: 6
Hello,
I've found this piece of code in Cfg2HbmTool.java :

Code:
public String columnAttributes(Column column, boolean isPrimaryKeyColumn)
    {
        StringBuffer sb = new StringBuffer();
        if(column.getPrecision() != 19)
            sb.append("precision=\"").append(column.getPrecision()).append("\" ");
        if(column.getScale() != 2)
            sb.append("scale=\"").append(column.getScale()).append("\" ");
        else
        if(column.getLength() != 255)
            sb.append("length=\"").append(column.getLength()).append("\" ");
...


I think that won't help me, but I'm just curious about why '19', '2' and '255' are "wrong" values, so if anybody knows...

Bye


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 04, 2008 8:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
they are the defaults hence no need to litter the hbm.xml files with redundant text.

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