-->
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.  [ 4 posts ] 
Author Message
 Post subject: Putting @id before variable id OR before getId() method ?
PostPosted: Thu Dec 23, 2010 5:19 am 
Beginner
Beginner

Joined: Wed Oct 08, 2008 10:59 am
Posts: 37
I have seen sample where Annotationsa re put directly before the declaration of the variable and other samples where it is put before the getXXXX() method. e.g.

@Id
@GeneratedValue(....)
private int id;

vs:

@Id
@GeneratedValue(....)
publci int getId() { ..... }


Is there a difference? I observed that putting the @Column(name = ...) before the getXXX() method does NOT create the column in the SQL TABLE. I have to write @Column before the variable declaration.

So are there diefferences between different types of Annotations?

Peter


Top
 Profile  
 
 Post subject: Re: Putting @id before variable id OR before getId() method ?
PostPosted: Thu Dec 23, 2010 5:49 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you can use either strategy, but you must be consistent with all your hibernate/jpa annotations:
if you declare @Id on the field, only annotations on fields will be considered;
if you declare @Id on a getter, only the getters will be considered.

Furthermore, Hibernate will write directly to the fields or use the setters according to your choice.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Putting @id before variable id OR before getId() method ?
PostPosted: Thu Dec 23, 2010 6:32 am 
Beginner
Beginner

Joined: Wed Oct 08, 2008 10:59 am
Posts: 37
Thank you.

But does that mean if I put @id before the variable declaration that getXXXX() and setXXXX() are never used?

Peter

s.grinovero wrote:
Furthermore, Hibernate will write directly to the fields or use the setters according to your choice.


Top
 Profile  
 
 Post subject: Re: Putting @id before variable id OR before getId() method ?
PostPosted: Thu Dec 23, 2010 7:26 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
But does that mean if I put @id before the variable declaration that getXXXX() and setXXXX() are never used?

Hibernate will not invoke those methods, you can still do it.

_________________
Sanne
http://in.relation.to/


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