-->
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: Custom Reverse Engineering
PostPosted: Sun Sep 11, 2011 1:43 am 
Newbie

Joined: Thu Feb 03, 2011 10:29 pm
Posts: 4
Hello Everyone,
When I reverse engineer my db, I would like to have some annotations added as well as a line of code, such as private static long serialVersionUID=1L. I have looked everywhere but I don't see any pointers on how to do it. I saw the ReverseEngineeringStrategy class, but that seems to pertain more to naming the getters and setters and the like.

I was wondering if anyone here could point me in the right direction as how to accomplish my aforementioned goals. The data is pretty skimp on the subject unless I am Googling the wrong keywords. Any help is greatly appreciated, thanks


Top
 Profile  
 
 Post subject: Re: Custom Reverse Engineering
PostPosted: Mon Sep 26, 2011 9:21 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
You need to change the templates.

Though I'm not sure why you would want to add serialVersionUID. The generated classes aren't supposed to be persisted through Java's serialization mechanism but in the database.
You could want serialize the Id classes in some circumstance. Still, I wouldn't bother with serialVersionUID unless your application design calls for it.

Re annotations: there are ways to add code to the class, in the form of <meta> elements.
Then there's also the Tools reference guide on docs.jboss.org. As you noticed, it's not very complete; <meta> is even less well documented, and I think it's even worse for the template engine.
The next best source of information would be the sources, which are readily available for download.
The forum is only a far-behind third. Seems like the devs went dormant (last posts from max and vyemialyanchyk seem to be from April/May 2011), so half-tested and half-understood recipes abound.

You may be better off avoiding reverse engineering. I found I needed to manually adjust a substantial fraction of the reveng information, and every single association; writing my own annotations would probably have gotten my project to fly earlier, taken less time, and moved all the relevant information outside that monolithic hibernate.reveng.xml where comments are too verbose, all the tables are thrown into a single place, and Eclipse's cross-referencing abilities are useless.
To verify that the manually crafted annotations (or .hbm.xml files) are correct enough for Hibernate to work with, set the Hibernate property hibernate.hbm2ddl.auto=validate (this can slow down the startup, so you may write yourself a trivial utility program that connects to the database and has just this setting different than the normal applications).
Caveat: I haven't tried doing manual reveng myself. I may be underestimating the effort needed to get the annotations/.hbm.xml right. I just know that I'm not happy with reveng, but moving away from that would be a major application overhaul so I'm not doing it (I'm on the verge of switching to Cayenne anyway, Hibernate's idea of long-running sessions seems fundamentally flawed to me).


Top
 Profile  
 
 Post subject: Re: Custom Reverse Engineering
PostPosted: Mon Sep 26, 2011 9:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
p.s. "long running"-sessions is *one* way of using hibernate - if it doesn't fit your approach then don't use that and just use detached objects.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Custom Reverse Engineering
PostPosted: Mon Sep 26, 2011 10:31 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Is there even a way to make long-running Sessions work?
I asked about that in viewtopic.php?f=1&t=1011933 and gave up on ever getting a response.

I didn't consider keeping objects detached as their normal state.
The book certainly doesn't explain things that way (that's why I overlooked that option), but it could indeed work.
I'll have to investigate my code and see how far I'll get with that.
[UPDATE] It doesn't work too well. Whenever some low software layer makes an update, it would have to mark that entity as "needs an update", nullifying the seamless integration (the promise of Hibernate is that low-level code does not need to care about whether the Java object is managed or not). The alternative would be that the high software levels know about what objects might have changed, and merge every one of them - I'm back at violating abstraction barriers.

Somewhat off-topic:
What's the word on getting dev answers here in the forum, is that something JBoss considers reserved for paying customers, is it a lack of hireable skilled manpower, is it too little funding, or what's going on?
I'd be happy with any answer, even if it's "you get what you pay for, pay or get lost". At least I'd then know what I can expect and what I can't, and could plan accordingly ;-)


Last edited by Joachim Durchholz on Thu Sep 29, 2011 9:00 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Custom Reverse Engineering
PostPosted: Tue Sep 27, 2011 8:12 pm 
Newbie

Joined: Thu Feb 03, 2011 10:29 pm
Posts: 4
Thanks everyone. I was able to customize the annotations needed in my application by using and modifying the Freemarker templates I found online. It was VERY difficult as there is no documentation available anywhere, but I was able to get it done. I only use the private long serialVer... because the IDE will complain if it is not there. I haven't reached the level where it makes a difference for me, I just want to get my proof of concept off the ground.

Thanks, UP.


Top
 Profile  
 
 Post subject: Re: Custom Reverse Engineering
PostPosted: Wed Sep 28, 2011 7:17 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
If you need this for Eclipse, you can switch the warnings off on a per-project basis.
Windows -> Preferences -> Java -> Compiler -> Warnings -> Errors/Warnings -> Potential programming problems -> Serializable class without serialVersionUID.

I found dealing with Freemarker templates painful, too. The main problem being that there's no documentation at all about which Javabeans of what types are set up by Hibernate Tools for Freemarker. I once tried to read the source, but I gave up once I found that tracing the data flow would probably take me a person-week.
That's why I try to stay away from the templates as far as possible.

That said, I did apply some changes, mostly to get rid of the generation date which was introducing gratuitious changes into our Subversion repository.
Unfortunately, this means I have to check the original templates for changes whenever I update Hibernate Tools, and reapply my changes. (Another reason to avoid doing much with the templates.)


Top
 Profile  
 
 Post subject: Re: Custom Reverse Engineering
PostPosted: Fri Jan 10, 2014 12:36 pm 
Newbie

Joined: Fri Jan 10, 2014 12:33 pm
Posts: 1
UbuntuPenguin wrote:
Thanks everyone. I was able to customize the annotations needed in my application by using and modifying the Freemarker templates I found online. It was VERY difficult as there is no documentation available anywhere, but I was able to get it done. I only use the private long serialVer... because the IDE will complain if it is not there. I haven't reached the level where it makes a difference for me, I just want to get my proof of concept off the ground.

Thanks, UP.


Could you put an example including source code?


Top
 Profile  
 
 Post subject: Re: Custom Reverse Engineering
PostPosted: Sat Jan 11, 2014 12:21 am 
Newbie

Joined: Thu Feb 03, 2011 10:29 pm
Posts: 4
@luisvt email me at justindallasREMOVETHIS@gmail.com and I'll see if I have the templates and relevant source somewhere.


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.