-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate - Annotations or Mappingfile
PostPosted: Wed Jun 23, 2010 5:27 am 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
Hello,

Im new to Hibernate and I would like to know what you personally would advice me to use:
Should I use Annotations for my Hibernate Configurations or a mapping-file?
What is easier and what will be used in future - what do you think?

Thanks for answering me!!


Top
 Profile  
 
 Post subject: Re: Hibernate - Annotations or Mappingfile
PostPosted: Wed Jun 23, 2010 11:16 am 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 67
I would say the answer would be ... yes.

In other words, I personally prefer using both. I like using annotations to show relationships, but I would avoid specifying database-specific information in your annotations, like table and column names, for instance.

This will result in some redundant information, which is obviously a disadvantage. It also means that many of your annotations are actually being ignored (entries in the mapping file for a property override the annotations). That's also unfortunate.

If you're trying to use pure JPA (including the mapping specification), you may find situations where you need to use a Hibernate-specific annotation because of some feature that you need. In that case, you may have to comment out the analogous entries in the mapping file (I prefer to do this instead of removing the entry), so the mapping file doesn't override the annotation.


Top
 Profile  
 
 Post subject: Re: Hibernate - Annotations or Mappingfile
PostPosted: Wed Jun 23, 2010 12:29 pm 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
thats interesting, thanks for your answer!
I will then use the mapping file, like I did before. Can you give me an example when using annotations is necessary? Im new and I try to learn as much and as fast as I can! :)


Top
 Profile  
 
 Post subject: Re: Hibernate - Annotations or Mappingfile
PostPosted: Wed Jun 23, 2010 1:53 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 67
Concerning when annotations are necessary, this would happen if you're strictly using JPA, with Hibernate (Kodo, OpenJPA, EclipseLink, TopLink, ...) as the implementation. The problem is that the JPA spec doesn't have any vendor extension mechanism for the mapping file. If a JPA implementation provides configurable added-value features (above the spec), there's no way to configure it in the mapping file. In those cases, the only option is to use the vendor-specific annotation.


Top
 Profile  
 
 Post subject: Re: Hibernate - Annotations or Mappingfile
PostPosted: Thu Jun 24, 2010 3:40 am 
Beginner
Beginner

Joined: Thu Jun 17, 2010 7:36 am
Posts: 26
ok, thank you very much for answering!


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