복붙노트

[SPRING] HIbernate 매핑 예외 : PropertyNotFoundException : setter를 찾을 수 없습니다.

SPRING

HIbernate 매핑 예외 : PropertyNotFoundException : setter를 찾을 수 없습니다.

나는 두 개의 POJO 's, STOCK 및 STOCK_DETAILS (일대 다 관계). 또한 하나의 인터페이스 IAUDITLOG (두 가지 방법이 있습니다) 있습니다. 나는이 인터페이스를 모두 POJO 's로 구현할 필요가 있고 그 메소드 내에서 일부 구현을 작성하려고한다. 하지만 자식 클래스 "STOCKDETAILS"와 IAUDITLOG 인터페이스를 구현하면 "setter 속성이 있어야 함"예외가 발생합니다.

스톡 클래스 :

@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 인터페이스 :

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

스택 추적 :

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)

아무나 알았어, 뭐가 문제가 될 수 있니? 왜 실제로 그 클래스에 속하지 않지만 다른 인터페이스에서 구현 된 속성에 대해 getter 및 setter를 만들어야합니다. FYI ... 부모 클래스 "STOCK"이이 인터페이스를 구현할 때이 잘 작동합니다.

해결법

  1. ==============================

    1.재정의 된 메서드에 @Transient를 사용하여 주석을 추가해야합니다.

    재정의 된 메서드에 @Transient를 사용하여 주석을 추가해야합니다.

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

    추신. Hibernate 3에서는 기본적으로 lazy이므로 lazy로 명시 적으로 표시 할 필요가 없다.

  2. ==============================

    2.이 문제를 해결하고 위의 해결 방법이 작동하지 않는 다른 사람들에게는 제 설정자의 이름이 정확하지 않습니다. 그것은 그것이 설정하고 있던 속성과 일치하지 않습니다. 그게 다야

    이 문제를 해결하고 위의 해결 방법이 작동하지 않는 다른 사람들에게는 제 설정자의 이름이 정확하지 않습니다. 그것은 그것이 설정하고 있던 속성과 일치하지 않습니다. 그게 다야

  3. from https://stackoverflow.com/questions/22032260/hibernate-mapping-exception-propertynotfoundexception-could-not-find-a-setter by cc-by-sa and MIT license