使用JPA和Hibernate作为提供者,我有一个类定义如下:
@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
。我会饶有兴趣!!!!
这在部署时发生。堆栈跟踪位于底部。
父类:
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;
}
}
Party类相当大,有很多映射。这是一个要求:
/**
* @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 :(得分:0)
您的问题可能与BaseDateRangeModel类相关联,因为PartyRole会扩展它。 你能告诉我们那堂课吗?
答案 1 :(得分:0)
你可以发布你的派对课吗?我怀疑这与你的多人映射有关。 partyRole表中是否有一个类型列?
答案 2 :(得分:0)
如果你在启动期间得到这个,这意味着你有一个类通过反向关系引用PartyRole的某个地方,例如
的内容@OneToMany(targetEntity=PartyRole.class, inverse=true")
在其他一些实体中。将休眠日志记录级别设置为DEBUG
- 它可以帮助您缩小问题范围。