-->
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.  [ 6 posts ] 
Author Message
 Post subject: Persistence problems for methods which start with get or is
PostPosted: Tue Mar 28, 2006 3:40 pm 
Newbie

Joined: Tue Mar 28, 2006 3:08 pm
Posts: 2
Hi,

In one of my entity classes I have defined these 2 methods:
public String getFirstName(){
return "";
}

public boolean isManager(){
return true;
}

I don't have the setter methods (setFirstName(..) and setManager(..)) nor the fields (String firstName; and boolean manager;) defined in my class.
Anyway when the class is persisted two columns are created in the database(FIRSTNAME and MANAGER).
What does this mean? That I have to annotate with @Transient every method which starts with get or is and I don't want to be persisted?
I think this is a bug.

I'm using: hibernate-3.2.0.cr1, hibernate-annotations-3.1beta9, hibernate-entitymanager-3.1beta7, hibernate-tools-3.1.0beta4 and ejb3-persistence(all of these built today from the SVN repository).

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 6:23 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
(I edited my response). I made the comment, and I realized you are using annotations... sorry, can't comment.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 6:29 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
Yet, I did managed to find this out of the docs:

Quote:
Every non static non transient property (field or method) of an entity bean is considered persistent, unless you
annotate it as @Transient. Not having an annotation for your property is equivalent to the appropriate @Basic
annotation. The @Basic annotation allows you to declare the fetching strategy for a property:


page 4 of
http://www.hibernate.org/hib_docs/annotations/reference/en/pdf/hibernate_annotations.pdf

Hope it helps!

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 6:49 pm 
Newbie

Joined: Tue Mar 28, 2006 3:08 pm
Posts: 2
Actually, the EJB3 Proposed Final Draft spec (sec. 2.1.1) states that:

Quote:
It is required that the entity class follow the method conventions for a JavaBean when persistent properties
are used.
In this case, for every persistent property property of type T of the entity, there is a getter method, get-
Property, and setter method setProperty. For boolean properties, isProperty is an alternative name for
the getter method.


In other words, in order for a bean to define a property, both setter and getter must be defined. It's not enough that only a get*() or is*() method exists.

Is this a case of Hibernate "relaxing" the definition of JavaBean property? If so, it should be made very clear as I'm sure lots of people would run into this issue.

It could also be that this interpretation of JavaBeans properties is used just while creating a schema from annotated classes, although I believe that the same metamodel is used at runtime too.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 7:32 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
what you say makes sense - I think we concluded that you did in fact need to put transient as an annotation.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject: Re: Persistence problems for methods which start with get or
PostPosted: Sat Apr 01, 2006 12:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
radus wrote:
That I have to annotate with @Transient every method which starts with get or is and I don't want to be persisted?

Correct

_________________
Emmanuel


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