-->
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.  [ 15 posts ] 
Author Message
 Post subject: Hibernate Annotator (H8A8) version 0.2 release
PostPosted: Wed Aug 17, 2005 5:56 pm 
Newbie

Joined: Wed Aug 17, 2005 5:37 pm
Posts: 5
I've released version 0.2 of H8A8, a tool to use Java 5 annotations for hibernate mapping.

http://peelmeagrape.net/h8a8/index.html

This is a Java 5 alternative to xdoclet, or to Hibernate Annotations / EJB3. Hopefully some may find it useful.

regards,
Eoin.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 7:28 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You know, instead of spending all that time on a clone of existing functionality, a converter for HBM files that produces EJB3/HB annotated Java source code would certainly get more attention from Hibernate users.

We'd also be interested what features in Hibernate Annotations you find missing.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 10:10 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
Hi, Christian,

Intresting idea! Is this your random thought or you guys have a plan for that?

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 3:41 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No plans, but its pretty obvious, right? There are thousands of people out there who probably want to migrate at some point. And its not too difficult to write such a software.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 3:43 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Actually, hbm2java might do this already.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 3:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, it can.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:06 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
But not for H2 mapping files :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 4:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it will actually do a pretty good job of it ;)

but in any case - hbm2java can do this, but we could need help to make it more complete (now it only handles the basic stuff)

So if someone wants to do that then please feel free to ask on how to contribute to that ;)

Skills needed: a craving for working with velocity templates and want to learn the small nerdy details of ejb3/hibernate mapping ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 2:47 pm 
Newbie

Joined: Wed Aug 17, 2005 5:37 pm
Posts: 5
christian wrote:
You know, instead of spending all that time on a clone of existing functionality, a converter for HBM files that produces EJB3/HB annotated Java source code would certainly get more attention from Hibernate users.

We'd also be interested what features in Hibernate Annotations you find missing.


I wrote this code back in May, so I'm not sure whether the situation has changed, but the way it happened was:
  • I was using xdoclet, and when I moved to Java 5 I found it didn't work
  • So I tried out Hibernate Annotations which was in a pretty early release.
  • I spent a lot of time trying to get it to work. Some of the problems I remember running into were:


I didn't want to change my database schema, so I took the xdoclet generated hbm files and started maintaining them by hand.

After a while it occurred to me that it would be quite easy to generate xml from annotations (by annotating the annotations themselves with mapping info). So I coded it up (to cover the subset of the dtd that I needed), which took less time than I had spent trying to get Hibernate Annotations to work. (There's really only about a 1000 lines of code in there - the rest is annotations/metadata.)

I'm using this successfully in production. I figured since I'd done the work I might as well release it. H8A8 works well as an interim solution for me, and I'm in no rush to move to EJB3 (I'm very happy with hibernate and have no need for portability to another EJB3 implementation)

I quite like the idea of a converter for hbm files to generate the java annotations. I attempted the hbm->ejb3 migration by hand and it was not straightforward, so I guess automating it would be quite involved.
To do a migration tool for the H8A8 annotations would be fairly doable - most of the mapping between the annotations and xml is already captured in metadata. I've already migrated my projects by hand though, so I'm not in a rush to implement a converter for H8A8 unless I get a lot of interest in it.

regards,
Eoin.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well - the advantage of the hibernate metamodel is that it is used by both the hbm and annotation binder and thus includes exactly the information needed to do it automatically...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 20, 2005 7:41 am 
Newbie

Joined: Wed Aug 17, 2005 5:37 pm
Posts: 5
max wrote:
well - the advantage of the hibernate metamodel is that it is used by both the hbm and annotation binder and thus includes exactly the information needed to do it automatically...


Of course. I assume the hbm model covers the entire metamodel, but from what I've seen the annotation binder doesn't yet do that. So the map from ejb3 annotations to the metamodel is not (in all cases) invertible.

Since (if) the hbm model covers the entire metamodel, then it also includes exactly the information needed.

When I was initially looking at Hibernate Annotations, I went through the code a bit to try and fix my problems. By nature of it's design it needs a lot of code like:
Code:
  if (annotatedClass.isAnnotationPresent(javax.persistence.Table.class) )

i.e. for each annotation / part of the metamodel, the binding has to be implemented by hand. This code is not reusable to implement the reverse mapping. If the reverse mapping was implemented it would have to be maintained separately.

My approach was to annotate my annotations, e.g.
Code:
  @XmlElement(name="class")
  @AddClassNameAsAttribute(name="name")
  public @interface H8Class

can generate
Code:
  <class name="my.EntityClass">

from
Code:
  @H8Class class EntityClass


and
Code:
  @XmlAttribute @DefaultFromGenericType(-1) String[] type() default {};

means that
Code:
  @H8Set(... ) Set<String> stuff;

can generate
Code:
  type="java.lang.String"


and adding new elements / attributes involves no coding.

Annotations and their properties map directly onto elements and attributes. So implementing the reverse map would be reasonably doable - and once implemented easy to maintain.

Maybe there is some analog to my approach whereby the hibernate metamodel could be annotated with the mapping needed by the hbm or annotation binder. If that was possible maybe the reverse mapping would work out cheaper to implement?

cheers,
eoin.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 20, 2005 12:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Your annotations are then driven purely by the xml schema which might not be the best way to specify it in annotations.

I like your solution for its generic transform back and forth - but generating from hibernate metamodel would be more valuable since we have specific "Binders" to handle the specific needs of XML, Annotations and JDBCMetaData ..... not possibly to do your trick without too much loss of specific functionallity (in my opinion)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 21, 2005 11:57 am 
Newbie

Joined: Wed Aug 17, 2005 5:37 pm
Posts: 5
max wrote:
Your annotations are then driven purely by the xml schema which might not be the best way to specify it in annotations.


True enough - they probably aren't exactly how you'd design them, though they don't work out too bad. Though they're maybe closer to how Hibernate Annotations would have been designed without the EJB3 requirement?

max wrote:
I like your solution for its generic transform back and forth - but generating from hibernate metamodel would be more valuable since we have specific "Binders" to handle the specific needs of XML, Annotations and JDBCMetaData ..... not possibly to do your trick without too much loss of specific functionallity (in my opinion)

/max


Yeah - I'm not familiar with the metamodel or the binder code too much. It was a convenient hack for what I wanted to do, but probably isn't generally applicable.

e.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 21, 2005 12:05 pm 
Newbie

Joined: Wed Aug 17, 2005 5:37 pm
Posts: 5
Another completely random thought - if you could read EJB3 annotations and generate XML (call it EJB3XML say), similarly to how I did - would it then be possible to convert that XML to hbm using XSLT? Or would the mapping from the EJB3 metadata to hbm/metamodel require other info from reflection on the classes? (EJB3 treating properties as persistent by default is one major difference in the mapping that occurs to me)

What I'm getting at is if there was code to take XML and generate the java source code for equivalent annotations then you could go HBM->EJB3XML->Source code and get the migration tool. (The problem with that is that not all HBM would be expressible as EJB3 i think).

But maybe writing the XSL for HBM->EJB3XML would be a lot of hassle. Maybe it'd just be easier to work through the HBM DTD and code the migration tool on an attribute-by-attribute basis.

eoin.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 21, 2005 12:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Yes, XSLT will seldomly be enough in these cases as it also need info from the classes - that is why hibernate metamodel is preferrable to use as a target/source for these conversions.

Please note that we have the migration tool in place for H3->Annotations, it just need to be made more complete to be truly usefull.

What could be interesting is a H2 to H3 hbm.xml transformation - for that XSLT should be enough (I think)

/max

_________________
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.  [ 15 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.