代码之家  ›  专栏  ›  技术社区  ›  Ben Noland

Hibernate-PropertyNotFoundException:找不到的getter

  •  12
  • Ben Noland  · 技术社区  · 16 年前

    public class MyClass {
        private String dPart1;
    
        public String getDPart1() {
            return dPart1;
        }
    
        public void setDPart1(String dPart1) {
            this.dPart1 = dPart1;
        }
    }
    

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

    我得到以下错误:

    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 
    

    看来hibernate不喜欢我的大写。我该怎么解决这个问题?

    10 回复  |  直到 16 年前
        1
  •  18
  •   Fortega    16 年前
    <property name="DPart1" not-null="true"/>
    

        2
  •  6
  •   dfa    16 年前

    对于名为“dPart1”的属性,hibernate将尝试使用名为“getDpart1”而不是“getDpart1” 停用物件审查卡

        3
  •  3
  •   Rune Sundling    16 年前

    access=“字段”

        4
  •  0
  •   Umesh Aawte    16 年前

    我找到解决办法了

    请将dPart1转换为dPart1,然后再次更改getter和setter。。

    记住还要更改xml。

        5
  •  0
  •   JuserNt    15 年前
    private String rptausu;
    
    public String getRptausu() {
        return rptausu;
    }
    
    public void setRptausu(String rpta) {
        rptausu = rpta;
    }
    

            <property name="prtausu" />
    

        6
  •  0
  •   Mike Demenok    14 年前

    根据我所看到的,Hibernate(至少是3.2.4版本)会期望像dPart这样的属性有一个名为getdPart:d的getter:d保持小写。看看dfa的答案吧——我猜其他版本可能会期待getDpart。

        7
  •  0
  •   Andrew Barber Eric Lafortune    12 年前

    getdPart1()
    setdPart1(....)
    

        8
  •  0
  •   Prasanna Kumar    11 年前

    对于房产

    设定者和接受者应该是

    setCarId(整数carId)

        9
  •  0
  •   askinss    8 年前

    在我最初使用的例子中,属性的命名约定很重要

    private String newimsi, getNewImsi();
    

    property not founder异常

    getNewimsi();