扩展AbstractAuditable(Spring数据)导致ManyToOne关系上的org.hibernate.MappingException

时间:2014-09-01 18:25:27

标签: hibernate jpa spring-data

我试图用JPA 2将我的实体映射到Hibernate作为提供者,但不幸的是我有一个例外,可能有几个人知道,但即使在网上看我也找不到一个 我想也许是因为我使用的是Spring Data JPA环境:

编辑我删除了extends AbstractAuditable并创建了ID,然后将错误移至另一个AbstractAuditable的实体,因此我使用此类错了吗?

stracktrace的相关部分说:

Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Collection, at table: car, for columns: [org.hibernate.mapping.Column(gearAssigments)]

涉及以下实体:

GearAssigment

@Entity
@Table(name = "gear_assigment")
public class GearAssigment extends AbstractAuditable<User, Integer> {

    private Integer usedQuantity;

    private Car car;

    private Gear gear;

    public GearAssigment(int id) {
        this.setId(id);
    }

    public GearAssigment() {
    }

    @Column(name = "used_quantity")
    public Integer getUsedQuantity() {
        return usedQuantity;
    }

    public void setUsedQuantity(Integer usedQuantity) {
        this.usedQuantity = usedQuantity;
    }

    @ManyToOne
    @JoinColumn(name = "car",referencedColumnName = "id")
    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    @ManyToOne
    @JoinColumn(name = "gear",referencedColumnName = "id")
    public Gear getGear() {
        return gear;
    }

    public void setGear(Gear gear) {
        this.gear = gear;
    }
}

汽车

@Entity
@Table(name = "car")
public class Car extends AbstractAuditable<User, Integer> {

    private String name;

    private Category category;

    private Collection<GearAssigment> gearAssigments;

    public Car(Integer id) {
        this.setId(id);
    }

    public Car() {
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "category")
    @Enumerated(EnumType.STRING)
    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @OneToMany(mappedBy = "car")
    public Collection<GearAssigment> getGearAssigments() {
        return gearAssigments;
    }

    public void setGearAssigments(Collection<GearAssigment> gearAssigments) {
        this.gearAssigments = gearAssigments;
    }
}

数据库上的所有表格都以id为主键,AbstractAuditable extends AbstractPersistable已将id colunm映射为@GeneratedValue,并与@MappedSuperClass进行映射{1}}

1 个答案:

答案 0 :(得分:0)

没关系,AbstractAuditable字段在字段级别使用javax.persistence注释进行注释,而不是像我在实体上那样在方法级别进行注释,因此您是否覆盖Spring的类或带注释的所有实体在现场级别的字段。所以Hibernate不要混合它们