12

I have a class that looks like the following:

public class MyClass {
    private String dPart1;

    public String getDPart1() {
        return dPart1;
    }

    public void setDPart1(String dPart1) {
        this.dPart1 = dPart1;
    }
}

My hibernate mapping file maps the property as follows:

<property name="dPart1" not-null="true"/>

I get the following error:

org.hibernate.PropertyNotFoundException: Could not find a getter for dPart1 in class com.mypackage.MyClass
        at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
        at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
        at org.hibernate.mapping.Property.getGetter(Property.java:272)
        at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:247)
        at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:125)
        at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
        at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
        at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)
        at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
        at 

It appears that hibernate doesn't like my capitalization. How should I fix this?

Ben Noland
  • 34,230
  • 18
  • 50
  • 51

10 Answers10

20
<property name="DPart1" not-null="true"/>

should work...

Fortega
  • 19,463
  • 14
  • 75
  • 113
  • I am also facing the problem and the above solutions works fine for me. Now what I would like to know is is it java specification for setter getter methods or is it jboss specific implementation for hibernate? Thank you for your answer :) – Kumar D Nov 15 '09 at 06:44
  • 1
    Could you please provide an explanation about your solution? – Marco Sep 13 '16 at 15:14
  • Could you elaborate? – Amirhosein Al Sep 25 '21 at 08:28
7

for a property called "dPart1" a hibernate will try a getter named "getDpart1" not "getDPart1" IIRC

dfa
  • 114,442
  • 31
  • 189
  • 228
4

Can't you just access it like a field?

access="field"

Rune Sundling
  • 592
  • 3
  • 8
0

The setter & getter should look like this

getdPart1()
setdPart1(....)

That's how the setters & getters are generated if generated through an IDE like eclipse.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
0

For a property private Integer carId;

the setters and getters should be

getCarId() setCarId(Integer carId)

0
private String rptausu;

public String getRptausu() {
    return rptausu;
}

public void setRptausu(String rpta) {
    rptausu = rpta;
}

mapping:

        <property name="prtausu" />

works correctly

0

The naming convention of the property matters example in my own case I initially used

private String newimsi, getNewImsi();

the above failed with same exception

propertynotfoundexception

until I corrected to below before it worked

getNewimsi();
askinss
  • 13
  • 8
0

Best Practice is not to create getters/setters by our self but use the Eclipse Shortcut(Alt+Shift+S) to create the same for the variables defined in a bean/pojo.

Naming convention does matters.

Piyush Upadhyay
  • 427
  • 4
  • 12
0

From what I've seen, Hibernate (at least version 3.2.4) will expect a property like dPart to have a getter named getdPart: d stays lowercase. Look at dfa's answer as well - I am guessing that other versions might expect getDpart instead.

Mike Demenok
  • 791
  • 8
  • 15
0

I got the solution

Please make dPart1 to dpart1 and change the getter and setter again..

It is working for me now.

Remember to change the xml also.