-->
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.  [ 11 posts ] 
Author Message
 Post subject: Property accessor naming conventions problem?
PostPosted: Tue Jan 03, 2006 7:53 am 
Newbie

Joined: Mon Apr 26, 2004 3:48 am
Posts: 18
Location: Istanbul, Turkiye
Hi all,

Think that i have member field mSomeValue in an Object. I am generating code from hibernate config file via ant tasks and it names the setter and getter as:

getmSomeValue
setmSomeValue

i supposed this is a bug play a bit with BasicPOJOClass.java to make some changes for generatiing the code as our project requires (method parameters starts with a, for example),

anyway now hibernate complains that cant find a getter for member xxx,

Even more interestingly Idea does the same thing while auto-generating the accessors but Eclipse not.

So is this a bug or is there something more I dont know about Javabean naming conventions.

Sorry for taking your time with strange topic, I dont like the convention, but whatever. (and sorry for the duplicate post, unintensionally I post same thing to Tools section.)

_________________
a y


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 8:22 am 
Newbie

Joined: Mon Apr 26, 2004 3:48 am
Posts: 18
Location: Istanbul, Turkiye
to be more precise:

hibernate cant find getter for member field mSomeValue

where getMSomeValue() method exists....

Has anyone got an idea about this?

_________________
a y


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 8:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
your property name is MSomeValue so use that instead of the wrong "mSomeValue"

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 8:31 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

I have also got the same problems, When i change the name of the variable from mSomeValue to msomeValue, Hibernate doesnt complain. Its Strange !!!!!!

If i am right the first two letters of the variables in the POJO Class should be same in LOWERCASE.

Try it out.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 9:21 am 
Newbie

Joined: Mon Apr 26, 2004 3:48 am
Posts: 18
Location: Istanbul, Turkiye
Max i didnt understand your post.

think an object Game. has field score. Our projects code conventions (which I dont like) says that member field name should start with m and continue uppecase.

so score becomes

mScore (not MScore!)

(which is not against any coding conventions even if it is ugly, sorry I cant break it:) guys here seem too preservative cause I joined the project too much later)

anyway getter for mScore is

getMScore which hibernate complains about. Let me know if this is is a bug, or am I wrong about it.

Thanx.

_________________
a y


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 10:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the FIELD is named mScore.
the PROPERTY is named MScore.

Thus use <property name="MScore"/>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 10:53 am 
Newbie

Joined: Mon Apr 26, 2004 3:48 am
Posts: 18
Location: Istanbul, Turkiye
Max, thank you for the point but this does not solve the problem because


if I name it mScore in hibernate config file as

<property name="MScore" ..

than hbm2java generates java field as:

MScore

Any suggestions?

_________________
a y


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 11:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Don't have double cased property names ;)

put a jira request for a naming strategy for the field names. (ugh)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 3:43 am 
Newbie

Joined: Mon Apr 26, 2004 3:48 am
Posts: 18
Location: Istanbul, Turkiye
I dont think this is something to do with a feature request with a naming strategy

class Game{
int score
}

is defined as

<property name="score"/>

and

class Game {
int mScore
}

is declared as

<property name="MScore"/>

?????

This is an obvious bug. Why make uppercase on this, keep lowercase on that? Your advice uppercasing the field name is just a workaround so that Hibernate can calculate the getter and setter as getMScore. where for field name mScore, it calculates it as getmScore which is a bug...

_________________
a y


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 5:19 am 
Newbie

Joined: Mon Apr 26, 2004 3:48 am
Posts: 18
Location: Istanbul, Turkiye
[from a faq]

I have a property named like getAFoo() / setAFoo() and Hibernate throws a PropertyNotFoundException at startup.

Use name="AFoo" as the property name in your mapping files. Don't report this issue as a bug, we know about it and we can't change it. If you insist on "first letter lowercase" naming of properties, use a custom access="my.PropertyAccessor" setting.


What is this ' access="my.PropertyAccessor" ' thing? Can someone explain?

Thank you.

_________________
a y


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 7:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hibernate is access the getter/setters for your properties - not *fields*.

Fields != Properties.

_________________
Max
Don't forget to rate


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