-->
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: [hbm2hbmxml] problems with db-objects named "abc$ta_tab
PostPosted: Thu Sep 07, 2006 5:34 am 
Newbie

Joined: Wed Sep 06, 2006 9:54 am
Posts: 9
Quote:
Hibernate version:
hibernate-3.1.3
HibernateTools-3.2.0.beta7, using the ant-tools!!!

Name and version of the database you are using:
Oracle9i 9.2.0.6.0


Hello out there,

i have an existing db-schema and named my db-objects like "abc$ta_tab_1", "abc$ta_tab_2", ... , "abc$ta_tab_n". first i do reverse engineering from the db with hbm2hbmxml. the generation of the hbm.xml-files works fine. but the generated xml contains some bugs.

in all generated "<many-to-one>"-relations the symbol "$" is replaced by the symbol ".". all other kind of generated references are ok.

so i have to edit the hbm.xml-files and replace the "." by "$". then i run "hbm2java". here, the generation of the java-code works find, too. but the java-code itselfs contains some bugs:

where the java-classes import other generated java-classes, the symbol "$" is replaces by the symbol ".", too.

a long long time ago, i did reverse engineering with middlegen for hibernate and hibernate2 based on the same db-schema and everything works fine. so i'm not sure, but is this a bug in hibernate-3.1.3 or did i some mistakes?

edit: the hibernate.reveng.xml-file i use contains only the following lines
Code:
<hibernate-reverse-engineering>
   <schema-selection match-schema="ABC_SCHEMA"/>
</hibernate-reverse-engineering>


best reguards
rig


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 4:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
submit some testcase describing it to jira (a *minimal* failing thing)

how did you rename the abc$ta_tab_1 in middlegen ? those names are not valid java...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 6:08 pm 
Newbie

Joined: Wed Sep 06, 2006 9:54 am
Posts: 9
max wrote:
those names are not valid java...

I use (generated with middlegen for hibernate2 and after changing the DOCTYPE in the hbm.xml-files from hibernate2 to hibernate3 currently running with hiberate-3.1.3) classnames like "pdc$taItem" or "pdc$taStatus" in Java (1.4.2 and 1.5) since more then one year and everything works fine. And from Sun's Java Tutorial clause "Naming":

Quote:
Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_". The convention, however, is to always begin your variable names with a letter, not "$" or "_". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged. White space is not permitted.

so, using the "$" is not notallowed ("should be avoid" is not "must be avoid" in my mind and it's autogenerated)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

max wrote:
how did you rename the abc$ta_tab_1 in middlegen

Take an editor (in this case "Kate") and replaced "." with "$" :-)

All jokes aside. I have e.g. 2 tables in my oracle-db: "PDC$TA_ITEM" and "PDC$TA_STATUS", with a foreign key references from "PDC$TA_ITEM" to "PDC$TA_STATUS". In my build.xml-File, I specified

Code:
<jdbcconfiguration packagename="com.foo.bar" />

The with hbm2hbmxml generated hbm.xml-Files named "pdc$taItem.hbm.xml" and "pdc$taStatus.hbm.xml". Because of the reference, the file "pdc$taItem.hbm.xml" contains amongst others following code:

Code:
<many-to-one name="taStatus" class="com.foo.bar.pdc.taStatus">
   <column name="STATUS_ID" />
</many-to-one>

Because i have a little bit notion of hbm.xml-files, i recognized, that com.foo.bar.pdc.taStatus are wrong. So I changed it to com.foo.bar.pdc$taStatus by hand, the spelling I know from middlegen for hibernate and run hbm2java. The ant-task generated all java-classes without errors. But when i opened the java-files with eclipse, I noticed that hbm2java genereted the following code in "taItem":

Code:
import com.foo.bar.pdc.taStatus;


When I change these to "import com.foo.bar.taStatus;, everything was fine in eclipse. But til now I had no opportunity presented itself for real-testing the generated javacode.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

At that time I started with hibernate2 and middlegen for hibernate, I did the same steps as now: existing db-schema -> hbm.xml-files -> java-classes. Unlike now the genereted hbm.xml-files called pdc_taItem.hbm.xml / pdc_taStatus.hbm.xml instead of pdc$taItem.hbm.xml / pdc$taStatus.hbm.xml today. And the generated JavaClasses called pdc$taItem.java / pdc$taStatus.java instead of taItem.java / taStatus.java today. When I don't want my JavaClasses named like the db-tables, I would specify an other name in the file "hibernate.reveng.xml".
In my mind as long as the names of the db-tables are valid JavaNames, they shouldn't be changed. If the names aren't valid JavaNames, throw an error while reverse engineering like "object name xyz is not a valid javaname. you have to specify a valid javaname in the hibernate.reveng.xml-file for these object."

best reguards
rig


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 6:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
put a *small* test/example for it in jira....but i don't promise anything since currently we have some code that strips out $ since it can be used to refer to inner classes in certain parts of the mapping files.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 12:27 pm 
Newbie

Joined: Wed Sep 06, 2006 9:54 am
Posts: 9
Hi,

max wrote:
put a *small* test/example for it in jira....but i don't promise anything since currently we have some code that strips out $ since it can be used to refer to inner classes in certain parts of the mapping files.


I have done so. Ticket-Number: HBX-751

reguards
rig


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.