-->
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.  [ 10 posts ] 
Author Message
 Post subject: Tools & Tools
PostPosted: Fri Apr 02, 2004 4:49 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
I noticed that for a regular primitive int, I get an Integer in my java files. Is there a way to keep the int? My route:

DB->middlegen->h2bm->java code...

Using the same route above, I ran into the following issues:

1. I would like to add a bunch of constants to my java classes, but I don't want them to be overwritten the next time I re-generate the code. Is there a way to have the generated code add a prefix or suffix like "Base" to its java class name -- like Torque?

That is, can the tool autogenerate a BaseAirline.java or HibernateAirline.java and then I can create an Airline.java that extends either BaseAirline.java or HibernateAirline.java.

Base on experience, auto-gen code is auto-gen code, that is, my experience taught me to never ever touch auto-gen code :-), so a solution like the above would be most helpful...

Thank-you...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 12:24 pm 
Newbie

Joined: Fri Apr 02, 2004 11:32 am
Posts: 5
If you wish to create abstract base classes from hbm2java, look at the documentation on <meta> tags.... specifically, <meta attribute="generated-class">


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 6:36 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Please elaborate. The documentation lacked a few details. I have about 100 tables and 100 classes and I would rather not having to go and add a meta tags manually to the mapping file.

Is there a global way to say, add or append a "Base" or "Hibernate" to the generated class name?

Also, would you know why my java class names are not the same as my database table names?

My table is called XYZAddress, but my java class name is called "XYZaddress.java". How do I change the code gen rules to use the exact same name for the java class as the database table, save the adding of a prefix or a postfix....

Thank-you for al your help!
Acco


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 8:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If you really want a base class for every class then put it on the jira and you'll get it - it is quite easy to implement .... noone has just never asked for it before ;)

But i guess you also want hbm2java to generate the concrete class, right ?

The naming stuff from table to class is something middlegen handles...look the docs for it - it got some parameters/java class that controls that naming.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 10:26 pm 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Yeah, I want the base classes and the bean classes that extend the base classes :-)

I'll checkout the Middlegen code-gen portion.

Thanks!!!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 12:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Middlegen has a JavaTypeMapper interface that you can implement to customise default type allocation. We do provide an existing Mapper implementation that I would recommend you try. It is not used by default. Alternatively, you can use the GUI to select the appropriate types.

The table name mapping is performed internally by Middlegen. I currently do not have a name mapper interface but I have been thinking about it. The class is simple enough to change if you find it necessary to do so. I don't have the code infront of me right now but the conversion you have suggested does not click. Anyway, get back to me if you have more questions.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 4:39 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Is this the type mapper you are refer to?


javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"

Thanks
Acco


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 12:41 am 
Regular
Regular

Joined: Tue Nov 11, 2003 7:35 pm
Posts: 63
Would it be acceptable for you to have a class named "AirlineBase" instead of "BaseAirline"? If so, you could define the suffix attribute in your hbm2java config file. For example, from section 19.2.1 of the docs you have the following config file:

Code:
<codegen>
    <meta attribute="implements">codegen.test.IAuditable</meta>
    <generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
    <generate
        package="autofinders.only"
        suffix="Finder"
        renderer="net.sf.hibernate.tool.hbm2java.FinderRenderer"/>
</codegen>


and says:

Quote:
The suffix attribute specifies the suffix for generated files. E.g. here a file named Foo.java would be FooFinder.java instead.


You could change the suffix to "Base" or whatever you want.

Also yes, the sample javaTypeMapper is javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper". You could create your own class though and use that one, you just need to implement the JavaTypeMapper interface. See the hibernate middlegen doc at http://www.hibernate.org/98.html .

Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 4:32 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Yes, that would work.

Thanks,
Anh

drosenbaum wrote:
Would it be acceptable for you to have a class named "AirlineBase" instead of "BaseAirline"? If so, you could define the suffix attribute in your hbm2java config file. For example, from section 19.2.1 of the docs you have the following config file:

Code:
<codegen>
    <meta attribute="implements">codegen.test.IAuditable</meta>
    <generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
    <generate
        package="autofinders.only"
        suffix="Finder"
        renderer="net.sf.hibernate.tool.hbm2java.FinderRenderer"/>
</codegen>


and says:

Quote:
The suffix attribute specifies the suffix for generated files. E.g. here a file named Foo.java would be FooFinder.java instead.


You could change the suffix to "Base" or whatever you want.

Also yes, the sample javaTypeMapper is javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper". You could create your own class though and use that one, you just need to implement the JavaTypeMapper interface. See the hibernate middlegen doc at http://www.hibernate.org/98.html .

Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 4:37 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Kudos for the docs btw. It's quite comprehensive!!!


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