Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: getter interpreted as property
PostPosted: Mon Aug 10, 2009 11:09 pm 
Newbie

Joined: Thu May 28, 2009 8:52 pm
Posts: 7
<access>PROPERTY</access>

public int getFoo() {
return 0;
}

This fails with
Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property foo

If the return type is complex like this,
public Bar getFoo() {
return new Bar();
}

Then it fails with this,
Caused by: org.hibernate.MappingException: Could not determine type for: com.example.model.impl.Bar, at table: User, for columns: [org.hibernate.mapping.Column(foo)]

Since there is no setter, this is not a bean property. So it should be ignored. Actually, it is ignored by OpenJPA and EclispseLink but Hibernate needs a transient. This causes the orm.xml to have more transients than the real properties.

I feel this is a bug. Can it be fixed?


Top
 Profile  
 
 Post subject: Re: getter interpreted as property
PostPosted: Tue Aug 11, 2009 8:20 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Could you compensate by making private setters?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: getter interpreted as property
PostPosted: Sun Aug 16, 2009 7:31 am 
Newbie

Joined: Thu May 28, 2009 8:52 pm
Posts: 7
Unfortunately, no. Its a huge application and not easy to go through all entities and add private setters.


Top
 Profile  
 
 Post subject: Re: getter interpreted as property
PostPosted: Tue Sep 01, 2009 10:44 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
p_pdd wrote:
Since there is no setter, this is not a bean property.

I don't agree - it's what I'd call a read-only-property...
Quite another question is, how hibernate should handle those read-only-properties...


Top
 Profile  
 
 Post subject: Re: getter interpreted as property
PostPosted: Tue Sep 01, 2009 4:45 pm 
Newbie

Joined: Thu May 28, 2009 8:52 pm
Posts: 7
piet.t wrote:
I don't agree - it's what I'd call a read-only-property...
Quite another question is, how hibernate should handle those read-only-properties...

See section 2.1.1 Persistent Fields and Properties of the spec, quoted below,
"It is required that the entity class follow the method signature conventions for JavaBeans read/write
properties
(as defined by the JavaBeans Introspector class) for persistent properties when persistent properties are used.
In this case, for every persistent property property of type T of the entity, there is a getter method, getProperty, and setter method setProperty. For boolean properties, isProperty is an alternative name for the getter method."

This also brings us to my other question,
viewtopic.php?f=1&t=999049

Clearly, from the spec, isProperty is an alternative for getter. So presence of isX and getX should not result in MappingException.

IMO, both of these are hibernate bugs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.