首页 > 解决方案 > org.hibernate.MappingException:无法确定类型:表中的类:table1,列:[org.hibernate.mapping.Column(end_table2)]

问题描述

我知道这种问题之前已经发布过。但是我在网上尝试了所有解决方案,但没有一个能解决我的问题。我从事Spring-MVC项目,在业务逻辑层中我定义了几个要映射到数据库的实体。我在 2 个类之间建立了多对多关系:MonumentCircuit. 但我得到这个错误

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)]

标签: javaspringhibernatespring-mvcjpa

解决方案


推荐阅读