使用注释的org.hibernate.MappingException

时间:2010-02-01 03:52:09

标签: java hibernate jpa

我正在为这两个类使用JPA注释:

@Entity
@RooJavaBean
@RooToString
@RooEntity
@MappedSuperclass
public abstract class BaseEntity {

  @Temporal(TemporalType.TIMESTAMP)
  @DateTimeFormat(style = "S-")
  private Calendar created;

  @Temporal(TemporalType.TIMESTAMP)
  @DateTimeFormat(style = "S-")
  private Calendar updated;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id")
  private Long id;

  @Version
  @Column(name = "version")
  protected Integer version;

  public Long getId() {
  return id;
  }

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

  public Integer getVersion() {
  return version;
  }

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

  @PrePersist
  protected void onCreate() {
  created = Calendar.getInstance();
  }

  @PreUpdate
  protected void onUpdate() {
  updated = Calendar.getInstance();
  }

}
@Entity
@RooJavaBean
@RooToString
@RooEntity
public class Event extends BaseEntity {

  private Score challenger;
  private Score defender;
  ...
}

@Entity
@RooJavaBean
@RooToString
@RooEntity
public class Score extends BaseEntity {

  @ManyToOne
  private Team team;
  private Event event;
  private Integer score;
  private Boolean accepted;
}

我得到一个例外:

Caused by: org.hibernate.MappingException: Could not determine type for: edu.unlv.cs.ladders.entities.Score, at table: event, for columns: [org.hibernate.mapping.Column(challenger)]
 at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:269)
 at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
 at org.hibernate.mapping.Property.isValid(Property.java:185)
 at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
 at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
 at org.hibernate.cfg.Configuration.validate(Configuration.java:1108)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1293)
 at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
 at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)

这是否与拥有两个访问同一类的单独字段有关?我是否必须更具描述性并指定列名称或其他内容?

1 个答案:

答案 0 :(得分:4)

您需要使用ScoreManyToOne注释OneToOne属性。