简体   繁体   English

HIbernate映射异常:PropertyNotFoundException:找不到setter

[英]HIbernate Mapping Exception: PropertyNotFoundException: Could not find a setter

I have two POJO's ,STOCK and STOCK_DETAILS (one to many relationship). 我有两个POJO,STOCK和STOCK_DETAILS(一对多的关系)。 Also I have one interface IAUDITLOG (having two methods). 我还有一个接口IAUDITLOG(有两种方法)。 I need to implement this interface with BOTH POJO's and want to write some implementation within those methods. 我需要用BOTH POJO实现这个接口,并希望在这些方法中编写一些实现。 But when I implement IAUDITLOG interface with child class "STOCKDETAILS" then it gives exception "that you should have setter property" 但是当我用子类“STOCKDETAILS”实现IAUDITLOG接口时,它会给出异常“你应该有setter属性”

STOCK CLASS: 股票类别:

@Entity
@Table(name = "stock")
public class Stock implements java.io.Serializable, IAuditLog
{   
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer stockId;

    @Column(name = "STOCK_CODE")
    private String stockCode;

    @Column(name = "STOCK_NAME")
    private String stockName;

    @OneToMany( fetch = FetchType.LAZY, mappedBy = "stock")
    public Set<StockDetail> stockDetails = new HashSet<StockDetail>(0);


    public Set<StockDetail> getStockDetails() {
        return stockDetails;
    }

    public void setStockDetails(Set<StockDetail> stockDetails) {
        this.stockDetails = stockDetails;
    }

    public Integer getStockId() {
        return stockId;
    }

    public void setStockId(Integer stockId) {
        this.stockId = stockId;
    }

    public String getStockCode() {
        return stockCode;
    }

    public void setStockCode(String stockCode) {
        this.stockCode = stockCode;
    }

    public String getStockName() {
        return stockName;
    }

    public void setStockName(String stockName) {
        this.stockName = stockName;
    }

// overridded methods of IAUDITLOG interface
    public int getLogId() {

        return stockId;
    }
    public String getLogDetail() {      
        return "some implementaion";
    }
}

STOCK DETAILS CLASS 库存详情类

@Entity
@Table(name = "StockDetail")
public class StockDetail implements Serializable, IAuditLog {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private Integer recordId;
    private Stock stock;
    private Float priceOpen;


    @Id
    @GeneratedValue
    @Column(name = "RECORD_ID", unique = true, nullable = false)
    public Integer getRecordId() {
        return this.recordId;
    }

    public void setRecordId(Integer recordId) {
        this.recordId = recordId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "STOCK_ID", nullable = false)
    public Stock getStock() {
        return this.stock;
    }

    public void setStock(Stock stock) {
        this.stock = stock;
    }

    @Column(name = "PRICE_OPEN", precision = 6)
    public Float getPriceOpen() {
        return this.priceOpen;
    }

    public void setPriceOpen(Float priceOpen) {
        this.priceOpen = priceOpen;
    }

    //overriddded methods of IADUTILOG inteface
    public int getLogId() {
        // TODO Auto-generated method stub
        return 0;
    }

    public String getLogDetail() {
        // TODO Auto-generated method stub
        return "some implementation";
    }
}

IAUDITLOg interface: IAUDITLOg界面:

public interface IAuditLog {
    public int getLogId();
    public String getLogDetail();
}

STACK TRACE: 堆栈跟踪:

Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:385)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1760)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1798)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
    ... 46 more
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:341)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
    ... 55 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
    ... 64 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property logDetail in class com.auditLog.common.StockDetail
    at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252)
    at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245)
    at org.hibernate.mapping.Property.getSetter(Property.java:326)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:201)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)
    ... 69 more

Feb 26, 2014 10:17:08 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet dispatcher
org.hibernate.PropertyNotFoundException: Could not find a setter for property logDetail in class com.auditLog.common.StockDetail
    at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252)
    at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245)
    at org.hibernate.mapping.Property.getSetter(Property.java:326)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:201)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:341)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

CAN ANYONE PLEASE LET ME KNOW,what could be the problem??? 请问任何人请让我知道,可能是什么问题? Why should I create getter and setter for those properties which is not ACTUALLY belongs to that class, but implemented from some other interface. 为什么我应该为那些非ACTUALLY属于该类的属性创建getter和setter,而是从其他一些接口实现。 FYI... this works fine when I implement this interface with Parent class "STOCK" 仅供参考...当我使用Parent类“STOCK”实现此接口时,此工作正常

You should annotate the overridden methods with @Transient. 您应该使用@Transient注释重写的方法。

http://docs.oracle.com/javaee/5/api/javax/persistence/Transient.html http://docs.oracle.com/javaee/5/api/javax/persistence/Transient.html

This annotation specifies that the property or field is not persistent. 此批注指定属性或字段不是持久的。 It is used to annotate a property or field of an entity class, mapped superclass, or embeddable class. 它用于注释实体类,映射的超类或可嵌入类的属性或字段。

Ps As of Hibernate 3 collections are lazy by default so there is no need to explicitly mark it as lazy. Ps从Hibernate 3开始,默认情况下是懒惰的,所以不需要明确地将它标记为懒惰。

For others who come across this and the above solution does not work, my error was that the name for my setter was not correct; 对于遇到此问题并且上述解决方案不起作用的其他人,我的错误是我的setter的名称不正确; it did not match the property it was setting. 它与它设置的属性不匹配。 That's all 就这样

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.PropertyNotFoundException:无法找到0的setter - org.hibernate.PropertyNotFoundException: Could not find setter for 0 PropertyNotFoundException:找不到设置器 - PropertyNotFoundException: Could not find a setter hibernate.PropertyNotFoundException:找不到具有多级映射Transformer的setter - hibernate.PropertyNotFoundException: Could not find setter with multi-level mapping Transformer Hibernate - PropertyNotFoundException:找不到 - Hibernate - PropertyNotFoundException: Could not find a getter for Hibernate找不到属性的setter(org.hibernate.PropertyNotFoundException) - Hibernate doesn't find setter for a property (org.hibernate.PropertyNotFoundException) 休眠:PropertyNotFoundException:找不到XXX的吸气剂 - Hibernate: PropertyNotFoundException: Could not find a getter for XXX org.hibernate.PropertyNotFoundException:找不到用于的吸气剂 - org.hibernate.PropertyNotFoundException: Could not find a getter for 休眠映射-在类中找不到属性名称的设置器 - hibernate mapping - Could not find a setter for property name in class 在没有名为“类型”的属性的类中,我得到org.hibernate.PropertyNotFoundException:在类中找不到属性类型的设置方法 - In class without a property called “type” I get org.hibernate.PropertyNotFoundException: Could not find a setter for property type in class org.hibernate.PropertyNotFoundException:在类Address中找不到customerId的获取方法 - org.hibernate.PropertyNotFoundException: could not find getter for customerId in class Address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM