我知道这类问题以前已经发布过。但是我在线尝试了所有解决方案,但是都没有解决我的问题。我从事的是 Spring-MVC 项目,在业务逻辑层中,我定义了多个要映射到数据库的实体。我在两个类之间建立了多对多关系:Monument
和Circuit
。但是我遇到了这个错误:
org.hibernate.MappingException: Could not determine type for: com.entities.Monument, at table: circuit, for columns: [org.hibernate.mapping.Column(end_monument)]
这是我的第一堂课:
@Entity
@Table(name = "monument")
public class Monument {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "latitude")
private double latitude;
@Column(name = "longtitude")
private double longtitude;
@Column(name = "name")
private String name;
@Column(name = "foundation_date")
private Date foundationDate;
@Column(name = "description")
private String description;
@ManyToMany(fetch = FetchType.LAZY, cascade = {
CascadeType.DETACH,
CascadeType.MERGE,
CascadeType.PERSIST,
CascadeType.REFRESH })
@JoinTable(name = "circuit_monument",
joinColumns = @JoinColumn(name = "monument_id"),
inverseJoinColumns = @JoinColumn(name = "circuit_id"))
private List<Circuit> circuits;
// constructors & getters é setters
}
我的第二堂课:
@Entity
@Table(name = "circuit")
public class Circuit {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "start_monument")
private Monument start;
@Column(name = "end_monument")
private Monument end;
@ManyToMany(fetch = FetchType.LAZY, cascade = {
CascadeType.DETACH,
CascadeType.MERGE,
CascadeType.PERSIST,
CascadeType.REFRESH })
@JoinTable(name = "circuit_monument",
joinColumns = @JoinColumn(name = "circuit_id"),
inverseJoinColumns = @JoinColumn(name = "monument_id"))
private List<Monument> monuments;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "circuit_id")
private List<Comment> comments;
// constructors & getters & setters
}
这是异常堆栈跟踪:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'touristController': Unsatisfied dependency expressed through field 'touristService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'touristServiceImp': Unsatisfied dependency expressed through field 'touristDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'touristDaoImp': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in com.configuration.AppConfig: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: com.entities.Monument, at table: circuit, for columns: [org.hibernate.mapping.Column(end_monument)]