-->
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.  [ 3 posts ] 
Author Message
 Post subject: Annotations Vs Hbm2Java
PostPosted: Sat Dec 16, 2006 1:26 pm 
Newbie

Joined: Tue Mar 07, 2006 3:37 am
Posts: 4
Hello,

We are starting a new project under Hibernate, and we would like to know which way is the best or easiest to work with.

1) Use HBM XMLs to create/maintain schema & then feed these XMLs to Hbm2Java so that POJOs will be generated for us. Later extend these POJOs as necessary.

OR

2) Use Java Annotations in the class and use these annotations to create HBM XMLs. Opposite of #1 above.

Our development team is split on this issue.

If we use #1 above in most cases we will have to extend the POJOs. But XMLs are compact and easier to maintain. Everything you need to know about a class is usually within 20 lines.

In #2 above, the maintenace becomes cumbersome since one has to scroll up and down or look at the generated XML to see the big picture. Plus we have to create the POJOs ourselves.

Thought we would approach the Hibernate community and learn from everyone's experience.

Thanks for your time & help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 4:45 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Well, if you can use Java 5, I'd advice you to use annotations (your #2), but you don't even need to generate XML. Look at Hibernate Annotations http://www.hibernate.org/397.html .

Moreover, this choice is the future of o/r mapping. This is using the EJB3/JPA specification, using the completely standard annotations from the javax.persistence package (obviously Hibernate is also providing some non standards annotations if you want to do things that standard do not [yet] permit).

Even Gavin King considers annotations to be the future default way to map your beans : http://www.javafree.org/content/view.jf?idContent=3
Quote:
In fact, I fully expect that this will be the most common way to use ORM in the future.


Your beans will look like this :
Code:
@Entity
public class Flight implements Serializable {
    Long id;

    @Id
    public Long getId() { return id; }

    public void setId(Long id) { this.id = id; }
}

http://www.hibernate.org/hib_docs/annot ... tml#d0e161

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 5:12 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
The main advantage of annotation is that the defaults are carefully choosen.

You do not have to tell Hibernate that a property should be mapped, which from my experience in the last project was very comfortable. Only details (unique constraints, field lengths for Strings, Timestamp/date/time) must be specified.

But XML is better supported by tools and more mature as compared to annotations.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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