gpt4 book ai didi

java - org.hibernate.MappingException 使用注解

转载 作者:行者123 更新时间:2023-11-29 04:03:02 26 4
gpt4 key购买 nike

我正在为这两个类使用 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;
}

不过我得到了一个异常(exception):

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)

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

最佳答案

您需要使用ManyToOneOneToOne注释Score属性。

关于java - org.hibernate.MappingException 使用注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2174568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com