-->
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.  [ 2 posts ] 
Author Message
 Post subject: Field names can't be single letter camel case?
PostPosted: Wed Mar 16, 2011 1:53 pm 
Regular
Regular

Joined: Tue Nov 30, 2004 4:23 pm
Posts: 62
I am using Hibernate 3.6, JPA 2.0, and Spring 3.0.6. I have fields in my objects like the following:

class PersonContact {
Long eAddressCpId;
ElectronicAddress eAddress;
}

I use field access (in my orm files) and queries/inserts/etc work without an issue. The fields are both in the class as well as in the orm files. But on startup of the application, the JPA configuration load spits out warnings:

2011-02-22 15:38:10,785 [[STANDBY] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] WARN org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader - Property com.foo.model.contactpoint.ElectronicAddress.eAddress not found in class but described in <mapping-file/> (possible typo error)
2011-02-22 15:38:10,801 [[STANDBY] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] WARN org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader - Property com.foo.model.person.PersonContact.eAddressCpId not found in class but described in <mapping-file/> (possible typo error)
2011-02-22 15:38:10,801 [[STANDBY] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] WARN org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader - Property com.foo.model.person.PersonContact.eAddress not found in class but described in <mapping-file/> (possible typo error)
2011-02-22 15:38:10,817 [[STANDBY] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] WARN org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader - Property com.foo.model.person.PartyContact.eAddressCpId not found in class but described in <mapping-file/> (possible typo error)
2011-02-22 15:38:10,817 [[STANDBY] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] WARN org.hibernate.cfg.annotations.reflection.JPAOverridenAnnotationReader - Property com.foo.model.person.PartyContact.eAddress not found in class but described in <mapping-file/> (possible typo error)

If I change my field names to be electronicAddressCpId and electronicAddress, then I don't get these warnings.

Is there requirements around the field names?

Thanks..jay


Top
 Profile  
 
 Post subject: Re: Field names can't be single letter camel case?
PostPosted: Wed Jan 25, 2012 6:26 pm 
Regular
Regular

Joined: Tue Nov 30, 2004 4:23 pm
Posts: 62
Thought I would post this answer here, I posted it on stackoverflow as well.

I found the problem and it is part of the method checkForOrphanProperties in JPAOverridenAnnotationReader:

Code:
for (Method method : clazz.getMethods()) {
    String name = method.getName();
    if ( name.startsWith( "get" ) ) {
        properties.add( Introspector.decapitalize( name.substring( "get".length() ) ) );
    }
    else if ( name.startsWith( "is" ) ) {
        properties.add( Introspector.decapitalize( name.substring( "is".length() ) ) );
    }
}


The problem is that the method looks for all public fields and then starts adding field names based on "get" and "is" methods it finds. The Introspector.decapitalize method utilizes specific rules to determine what to decapitalize.


From the Introspector class:

Code:
/**
* Utility method to take a string and convert it to normal Java variable
* name capitalization.  This normally means converting the first
* character from upper case to lower case, but in the (unusual) special
* case when there is more than one character and both the first and
* second characters are upper case, we leave it alone.
* <p>
* Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays
* as "URL".
*
* @param  name The string to be decapitalized.
* @return  The decapitalized version of the string.
*/
public static String decapitalize(String name) {
if (name == null || name.length() == 0) {
    return name;
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
        Character.isUpperCase(name.charAt(0))){
    return name;
}
char chars[] = name.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
return new String(chars);
}


So for instance our field is:

Code:
private String eAddress;


And our getter is:

Code:
public String getEAddress() {
        return eAddress;
}


So based on the Introspector.decapitalize functionality, the result of the decapitalize would be "EAddress", not "eAddress". Because it sees two capital letters in the "EAddress" when the code substrings off the "get"...it won't decapitalize those. Therefore it complains that the eAddress field in the orm.xml doesn't exist. The persistence of the field works totally fine, these warnings just show up when the war starts and the files are bootstrapped.


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