-->
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.  [ 15 posts ] 
Author Message
 Post subject: id with Uppercase char at 2. pos give error
PostPosted: Wed Mar 10, 2004 11:52 pm 
Beginner
Beginner

Joined: Fri Mar 05, 2004 11:14 am
Posts: 38
Location: Houston, Texas
I do not know if this already has been posted. I have found a way around this and just want to let you know.


Having the example below won't work with the id having name "rSeisProcActS" but using "rseisProcActS" works !


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class
name="com.xyz.model.PbRSeisProcActV"
table="PB_R_SEIS_PROC_ACT_V"
>

<id
name="rSeisProcActS"
column="R_SEIS_PROC_ACT_S"
type="java.lang.String"
length="19">
<generator class="com.xyz.hibernate.SurrogateKeyGenerator"/>
</id>

<property
name="processingNm"
column="PROCESSING_NM"
type="java.lang.String"
length="40"
/>
<property
name="superKind"
column="SUPER_KIND"
type="java.lang.String"
length="40"
/>
<property
name="description"
column="DESCRIPTION"
type="java.lang.String"
length="2000"
/>


<!-- associations -->

</class>
</hibernate-mapping>



Gives : Could not find a setter for property rSeisProcActS in class com.xyz.model.PbRSeisProcActV

But the generated java looks correct like

package com.xyz.model;

import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/** @author Hibernate CodeGenerator */
public class PbRSeisProcActV implements Serializable {

/** identifier field */
private String rSeisProcActS;

/** nullable persistent field */
private String processingNm;

/** nullable persistent field */
private String superKind;

/** nullable persistent field */
private String description;

/** full constructor */
public PbRSeisProcActV(String processingNm, String superKind, String description) {
this.processingNm = processingNm;
this.superKind = superKind;
this.description = description;
}

/** default constructor */
public PbRSeisProcActV() {
}

public String getRSeisProcActS() {
return this.rSeisProcActS;
}

public void setRSeisProcActS(String rSeisProcActS) {
this.rSeisProcActS = rSeisProcActS;
}

public String getProcessingNm() {
return this.processingNm;
}

public void setProcessingNm(String processingNm) {
this.processingNm = processingNm;
}

public String getSuperKind() {
return this.superKind;
}

public void setSuperKind(String superKind) {
this.superKind = superKind;
}

public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

public String toString() {
return new ToStringBuilder(this)
.append("rSeisProcActS", getRSeisProcActS())
.toString();
}

public boolean equals(Object other) {
if ( !(other instanceof PbRSeisProcActV) ) return false;
PbRSeisProcActV castOther = (PbRSeisProcActV) other;
return new EqualsBuilder()
.append(this.getRSeisProcActS(), castOther.getRSeisProcActS())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getRSeisProcActS())
.toHashCode();
}

}


Making this correction to the mapping file (setting name=rseisProcActS" ) fixes the problem.

Must be a error in the code which gets confused with the uppercase in the 2. char



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class
name="com.xyz.model.PbRSeisProcActV"
table="PB_R_SEIS_PROC_ACT_V"
>

<id
name="rseisProcActS"
column="R_SEIS_PROC_ACT_S"
type="java.lang.String"
length="19">
<generator class="com.xyz.hibernate.SurrogateKeyGenerator"/>
</id>

<property
name="processingNm"
column="PROCESSING_NM"
type="java.lang.String"
length="40"
/>
<property
name="superKind"
column="SUPER_KIND"
type="java.lang.String"
length="40"
/>
<property
name="description"
column="DESCRIPTION"
type="java.lang.String"
length="2000"
/>


<!-- associations -->

</class>
</hibernate-mapping>


The generated code for this is (correctly as well)

package com.xyz.model;

import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/** @author Hibernate CodeGenerator */
public class PbRSeisProcActV implements Serializable {

/** identifier field */
private String rseisProcActS;

/** nullable persistent field */
private String processingNm;

/** nullable persistent field */
private String superKind;

/** nullable persistent field */
private String description;

/** full constructor */
public PbRSeisProcActV(String processingNm, String superKind, String description) {
this.processingNm = processingNm;
this.superKind = superKind;
this.description = description;
}

/** default constructor */
public PbRSeisProcActV() {
}

public String getRseisProcActS() {
return this.rseisProcActS;
}

public void setRseisProcActS(String rseisProcActS) {
this.rseisProcActS = rseisProcActS;
}

public String getProcessingNm() {
return this.processingNm;
}

public void setProcessingNm(String processingNm) {
this.processingNm = processingNm;
}

public String getSuperKind() {
return this.superKind;
}

public void setSuperKind(String superKind) {
this.superKind = superKind;
}

public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

public String toString() {
return new ToStringBuilder(this)
.append("rseisProcActS", getRseisProcActS())
.toString();
}

public boolean equals(Object other) {
if ( !(other instanceof PbRSeisProcActV) ) return false;
PbRSeisProcActV castOther = (PbRSeisProcActV) other;
return new EqualsBuilder()
.append(this.getRseisProcActS(), castOther.getRseisProcActS())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getRseisProcActS())
.toHashCode();
}

}



Well anyhow - somwhere ther eis a bug which dose not like property Names to have a upper case char in 2. position....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 4:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If your getter is called getRseisProcActS, the property has to be called rseisProcActS as in the JavaBean spec.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 5:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You did not say how you "generated" the mapping. It would help to know. In anycase, Middlegen did have this problem. The fix was already in CVS.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 11:27 am 
Beginner
Beginner

Joined: Fri Mar 05, 2004 11:14 am
Posts: 38
Location: Houston, Texas
Yes - middlegen was used. But its really irrelevant. As long as the generated Java is correct it must be a bug in Hibernate ?
I see middlegen has "fixed" it by not making sunch property names but that is just a workaround and not explaining why it dose not work

Anyhow - I just wanted to let you know. Still think Hibernate is a great product.

B


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 11:31 am 
Beginner
Beginner

Joined: Fri Mar 05, 2004 11:14 am
Posts: 38
Location: Houston, Texas
Reply to Michael - you are right - and that is also the one which works. (second in my example) but the first example (the one which fails) has a property called

rSeisProcActS

and the setter and getter are generated (correctly according to spec) as

public String getRSeisProcActS() {
return this.rSeisProcActS;
}

public void setRSeisProcActS(String rSeisProcActS) {
this.rSeisProcActS = rSeisProcActS;
}


but THAT fails !

B


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 12:13 pm 
Newbie

Joined: Thu Apr 01, 2004 12:06 pm
Posts: 12
Location: Hamburg (Germany)
I'm having the same problem:

I have a property with an upper case char in second position:

Code:
<property
        name="pKey"
        type="java.lang.String"
        column="P_KEY"
        not-null="true"
        length="8"
    />


the java getter is correctly generated by hbm2java (IMHO):
Code:
/** persistent field */
  private String pKey;

public java.lang.String getPKey() {
        return this.pKey;
}


but when I try an Configuration.addFile() I get the error:
Code:
net.sf.hibernate.PropertyNotFoundException: Could not find a getter for pKey in class test.Property


Changing the name to propKey or something like this works.
Am I'm missing something, is this expected JavaBeans behavior?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
shouldn't it be name="PKey" ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 2:31 pm 
Beginner
Beginner

Joined: Fri Mar 05, 2004 11:14 am
Posts: 38
Location: Houston, Texas
No. - As Michale stated - The Java Bean spec uppercases the first letter in the getter. So a property with the name "pKey" get's the correct getter "getPKey". So the XML file is correct and the getter is correctly generated - still Hibernate fails.

I still beleave there is something rotten.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 12:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Im not going to say right or wrong as I am not a Bean Spec expert. Having said that, the Middlegen Plugin (in CVS) will not allow the second char to be uppercase in this situation now thus avoiding this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 8:11 am 
Newbie

Joined: Thu Apr 01, 2004 12:06 pm
Posts: 12
Location: Hamburg (Germany)
Quote:
Im not going to say right or wrong as I am not a Bean Spec expert. Having said that, the Middlegen Plugin (in CVS) will not allow the second char to be uppercase in this situation now thus avoiding this issue.


That is good - however it doesn't help me, since I need my Middlegen properties file, which I have to edit by hand to change the 2nd char to lowercase.

But leaving Middlegen out:
Code:
<property
        name="pKey"
        type="java.lang.String"
        column="P_KEY"
        not-null="true"
        length="8"
    />


is a perfectly valid Hibernate mapping, so I would hibernate expect to handle this without errors.


Top
 Profile  
 
 Post subject: Introspector.decapitalize
PostPosted: Fri Apr 09, 2004 3:22 am 
Newbie

Joined: Fri Apr 09, 2004 2:01 am
Posts: 6
Location: Kiev, Ukraine
The source of that problem is in using Introspector.decapitalize() method. From javadoc: when there is more than one character and both the first and second characters are upper case, we leave it alone. As this ugly (decapitalize otput is capitalized!) behaviour is well documented, it is not considered to be a bug and will not be fixed. Thus we have to ask Hibernate team to write their own method instead of using a standard but inappropriate one.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 10, 2004 3:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Create a JIRA entry for this with your comment and a reference to this thread. This way it will be forgotten as Hiernate v3.0 is the primary focus at the moment.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 10, 2004 4:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Negative. Please don't create any more JIRA issues relating to this, since I will just reject them.


Top
 Profile  
 
 Post subject: So what should I do???
PostPosted: Tue Apr 13, 2004 5:34 am 
Newbie

Joined: Fri Apr 09, 2004 2:01 am
Posts: 6
Location: Kiev, Ukraine
I'm completely confused. Will this behaviour be changed in 3.0 or not? As I've already mentioned, Sun doesn't plan to change decapitalize implementation and using such names in databases is quite common (e_mail, a_bomb etc). I use middlegen to generate .hbm files, then have to edit them manually and only then may call hbm2java. Does a better alternative exist?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 10:45 am 
Beginner
Beginner

Joined: Fri Mar 05, 2004 11:14 am
Posts: 38
Location: Houston, Texas
Hmm - I'm also a little confused. Sounds like there must have been a dicussion around this before ? Any link ?

It cooks down to the fact that if

1) I create a mapping file with a property which has a Uppercase letter as 2. char, example rAbc
2) Use hbm2java to create java files

than it won't work.

We can leave all discussions around Middlegen etc out of this and focus on the fact that a fully valid property name of "rAbc" + hbm2java generated java won't work. But maybe this has a deeper reason which I am not aware of .... anyhow it's not a big deal - so we could perhapst just add this "feature" to the FAQ ?

Thanx again
B-)


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