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.  [ 7 posts ] 
Author Message
 Post subject: reverse engineering and mapping scheme dilema
PostPosted: Sun Mar 20, 2005 4:18 am 
Beginner
Beginner

Joined: Sun Jul 25, 2004 11:15 pm
Posts: 24
Hi forum!

I recently started learning how to use hibernate. I started with hibernate 3 and the eclipse plugin tools(still alpha).

I am having a dilema with the way I am doing things. Here is a breif explanation of the problem, and I hope someone would be able to guide me in the right direction. Please be gentle as I am a beginner.


I have an existing database that i reverse engineer (using the new eclipse artifact generator) to get the xml mappings.
I then manually edit the mappings to fix some stuff, and change some stuff (since the artifact generator or the reverse engineering tool is still in alpha and has some quirks)

From these manually edited mapping files, I generate the java code.

In the java code, I also need to add some methods, and other things that are not related to or needed by hibernate.

All this works fine untill there is a change in the database, or if i change something in the mapping file for some reason. In that case, I need to regenerate the java code and thus, my changes in the java file are gone.

One solution I thought of was to extend the generated classes and put my methods and other non-hibernate related work in these subclasses, and use those with hibernate, but it seems that does not work because the mappings don't work with my new classes because they were done for the generated classes.

I would appreciate if someone can tell me how to go about doing this?

Many thanks
H.S.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 20, 2005 4:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
a couple of things here...lets start with the easy ones.

1. having the codegenerator generate baseclasses instead of the concrete classes so you can add your logic to them.

See <meta attribute="generated-class"/> (note that in the alph1 there is a bug so you can only change the class name, and not the package name - that is fixed in cvs)

2. having the reverse generator output be more complete/aligned with what you want.

- some stuff is already done, but not exposed in the gui (such as controlling name standards, type mappings etc.)
- other stuff I havent done yet and like input, so tell me what it is you are changing and i can tell you if it is something we can handle.

But do note that rev.eng. can only be somewhat "redoable". If you have some or-model that doesnt fit well with the schema you are probably better out with just generate the mapping files once and then edit by hand in the future (we are planning on making a tool that tell you what is *not* in the mappings but in the db and vice versa - contributions wanted :)

did that help ? ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 20, 2005 5:50 am 
Beginner
Beginner

Joined: Sun Jul 25, 2004 11:15 pm
Posts: 24
Max:
Thank you for the quick responses (on a Sunday too!)
I looked in the documentation for the generated-class and found this:

generated-class overrule the name of the actual class generated

I honestly did not understand it well. Is there anywhere else where this is explained in more details?
I am looking here:
http://www.hibernate.org/hib_docs/v3/re ... ml_single/

and that was the only match of "generated-class"

As for things i am changing in the mapping files, it has so far been to work around some bugs that you indicated you have already fixed (or still working on) such as the boolean type in hsqldb, the "generated" vs "native" id, and such.

I am sure once i dig deeper into this, I will have more and more. At this point I am still trying to get myself up-to-speed with hibernate and eclipse as i am new to both.

Thank you for all your help and the super quick responses.
Keep up the good work!
Cheers
H.S.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 20, 2005 7:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
just try to use generated-class and you will see it ,)

or search this forum for generated-class, enough threads about it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 20, 2005 3:08 pm 
Beginner
Beginner

Joined: Sun Jul 25, 2004 11:15 pm
Posts: 24
Max:

Ok, after reading some posts on this forum, I thought i need to do this:

<class
name="some.package.Category"
table="CATEGORY"
>
<meta attribute="generated-class">some.package.DbCategory</meta>

This seems to have no effect. I am still getting a concrete Category class, and nothing else. According to some of the posts I read, an abstract class should be generated. Is that true?

is there something I am still doing wrong?

Thanks
H.S.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 20, 2005 3:37 pm 
Hibernate Team
Hibernate Team

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

you are running the artifact generator without enabling reverse engineering, correct ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 20, 2005 8:34 pm 
Beginner
Beginner

Joined: Sun Jul 25, 2004 11:15 pm
Posts: 24
You're THE man, max.

I was enabling the reverse engineering.
Once i turned that off, it worked.

thank you so much.


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