2009-07-31 17 views
0

類屬性類型二傳手使用JPA和Hibernate作爲provideer,我定義了諸如一類:在類沒有所謂的財產「式的」我得到org.hibernate.PropertyNotFoundException:找不到在

@Entity 
@Table(name="partyrole") 
public class PartyRole extends BaseDateRangeModel { 
    private static final long serialVersionUID = 1L; 
    private Party roleFor; 

    public void setRoleFor(Party roleFor) { 
    this.roleFor = roleFor; 
    } 

    @ManyToOne 
    public Party getRoleFor() { 
    return roleFor; 
    } 
} 

我得到了問題標題中的錯誤。我試過添加public void setType(Object type),但那也行不通。 persistence.xml文件是正常的。 有兩個類引用這個類,但它們都不會嘗試調用setType。我會apprecaite任何幫助! 這發生在部署時。堆棧跟蹤位於底部。

父類:

package com.nsfw.bmp.common.jpa; 

import java.util.Date; 

import javax.persistence.Column; 
import javax.persistence.MappedSuperclass; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 
import javax.persistence.Transient; 

import org.hibernate.validator.AssertTrue; 
import org.hibernate.validator.NotNull; 

/** 
* Several models are date range sensitive, this base class provides that basic 
* functionality. 
* 
* @author jim 
* 
*/ 
@MappedSuperclass 
public abstract class BaseDateRangeModel extends BasePersistentModel { 
private static final long serialVersionUID = 1L; 
private Date from; 
private Date thru; 

/** 
* Determines if a model is active. A model is active if now is after or 
* equal to from , and thru is either null, or after now, or equal to now. 
*/ 
@Transient 
public boolean isActive() { 
    Date now = new Date(); 
    boolean afterFrom = from.before(now) || from.equals(now); 
    boolean beforeThru = thru == null || thru.after(now) 
      || thru.equals(now); 
    return afterFrom && beforeThru; 
} 

@AssertTrue(message = "Dates are not valid the thru date must be empty, or after the fromdate.") 
public boolean areDatesValid() { 
    if (thru == null) { 
     return true; 
    } else { 
     return thru.after(from); 
    } 
} 


@Temporal(TemporalType.TIMESTAMP) 
@NotNull 
@Column(name = "fromDate") 
public Date getFrom() { 
    return from; 
} 

public void setFrom(Date from) { 
    this.from = from; 
} 

@Temporal(TemporalType.TIMESTAMP) 
public Date getThru() { 
    return thru; 
} 

public void setThru(Date thru) { 
    this.thru = thru; 
} 

}

其母公司:

package com.nsfw.bmp.common.jpa; 

import java.io.Serializable; 

import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.MappedSuperclass; 
import javax.persistence.Version; 

@MappedSuperclass 
public abstract class BasePersistentModel implements Serializable{ 

/** 
* 
*/ 
private static final long serialVersionUID = 1L; 

protected Long id; 

protected Long version = 0l; 

@Override 
public boolean equals(Object obj) { 
    if (this == obj) 
     return true; 
    if (obj == null) 
     return false; 
    if (getClass() != obj.getClass()) 
     return false; 
    BasePersistentModel other = (BasePersistentModel) obj; 
    if (id == null) { 
     if (other.id != null) 
      return false; 
    } else if (!id.equals(other.id)) 
     return false; 
    if (version == null) { 
     if (other.version != null) 
      return false; 
    } else if (!version.equals(other.version)) 
     return false; 
    return true; 
} 

@Id 
@GeneratedValue 
public Long getId() { 
    return id; 
} 

@Version 
public Long getVersion() { 
    return version; 
} 

@Override 
public int hashCode() { 
    final int prime = 31; 
    int result = 1; 
    result = prime * result + ((id == null) ? 0 : id.hashCode()); 
    result = prime * result + ((version == null) ? 0 : version.hashCode()); 
    return result; 
} 

public void setId(Long id) { 
    this.id = id; 
} 

public void setVersion(Long version) { 
    this.version = version; 
} 

}

黨類是相當大的,用了很多的映射。這是一個要求:

/** 
* @return the actingAs 
*/ 
@OneToMany(mappedBy="roleFor", targetEntity=com.nsfw.bmp.party.entity.association.PartyRole.class) 
@OrderBy("from") 
public List<PartyRole> getActingAs() { 
    return actingAs; 
} 

這裏的堆棧跟蹤:

Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property type in class com.nsfw.bmp.party.entity.association.PartyRole 
at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:240) 
at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:233) 
at org.hibernate.mapping.Property.getSetter(Property.java:299) 
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:272) 
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:149) 
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:76) 
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80) 
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:325) 
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:457) 
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131) 
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84) 
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327) 
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867) 
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669) 
+0

你什麼時候得到錯誤?當你插入/更新?運行查詢?啓動應用程序?你能發佈完整的堆棧跟蹤嗎? – ChssPly76 2009-07-31 17:05:06

+0

在服務器上進行部署期間。 – 2009-08-01 17:18:09

回答

0

你可以發佈你的派對課嗎?我有一個懷疑,這與你的manytoone映射有關。 partyRole表中是否存在類型列?

0

您的問題可能會被鏈接到BaseDateRangeModel類,因爲成員角色進行了擴展。 你能告訴我們那堂課嗎?

0

如果您在啓動過程中遇到此問題,則表示您有一個類通過反向關係引用PartyRole,例如,東西沿線

@OneToMany(targetEntity=PartyRole.class, inverse=true") 

在一些其他實體。將休眠日誌記錄級別設置爲DEBUG - 它應該可以幫助您縮小問題的範圍。