相关疑难解决方法(0)

Hibernate Mapping Exception:实体映射中的重复列

特定实体存在映射异常.无法从问题出现的地方找出答案.我从头到尾检查了所有映射3次.我仍然得到映射异常.

发送给员工的电子邮件只映射一次.但它仍然报告错误重复映射

错误是:

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.cluster.entity.Email column: EMPLOYEE_ID (should be mapped with insert="false" update="false")
    at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:680)
    at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:702)
    at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:724)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:477)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:268)
    at org.hibernate.cfg.Configuration.validate(Configuration.java:1287)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1729)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
    at com.cluster.util.HibernateUtil.<clinit>(HibernateUtil.java:16)
    ... 1 more
Run Code Online (Sandbox Code Playgroud)

电子邮件Pojo

package com.cluster.entity;

public class Email {

    private int intEmailID;
    private String strEmailName;

    //many to one
    private EmailType emailType;

    //many to one
    private Employee employee;

    public int getIntEmailID() {
        return intEmailID;
    }

    public void setIntEmailID(int intEmailID) {
        this.intEmailID …
Run Code Online (Sandbox Code Playgroud)

orm persistence hibernate hibernate-mapping java-ee

11
推荐指数
2
解决办法
4万
查看次数

删除实体时,Hibernate将外键设置为null

我有以下hibernate entites:

@Entity
@Table(name = "model_view")
public class ModelView {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "modelView_id")
    private Integer id;

    @ManyToOne
    @NotNull
    @JoinColumn(name = "page_id", nullable = false, insertable = true, updatable = true)
    private Page page;

    /* getters and setters */
}
Run Code Online (Sandbox Code Playgroud)

和:

@Entity
public class Page {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "page_id")
    private Integer id;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "page_id")
    @IndexColumn(name = "modelView_id")
    private Set<ModelView> modelViews = new HashSet<ModelView>();

    /* getters and …
Run Code Online (Sandbox Code Playgroud)

hibernate

11
推荐指数
1
解决办法
2万
查看次数

休眠更新为空,然后尝试通过更新的列删除

我只想从数据库中删除那些未使用的属性(orphanRemoval=true)。我得到的是它首先尝试更新参考 PRODUCT_ID,然后删除它。但由于参考是键的一部分,它不能。

家长:

    @Entity
    @Table(name = "STYLE")
    public class Style implements IterableById, Serializable {
    ...
        @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval=true)
        @JoinColumn(name="PRODUCT_ID", referencedColumnName = "PRODUCT_ID")
        private List<Attribute> attributes;
    ...
Run Code Online (Sandbox Code Playgroud)

它的孩子

    @Entity
    @Table(name="ATTRIBUTE")
    public class Attribute{
        @EmbeddedId
        private Id id;
        ...

        @Embeddable
        public static class Id implements Serializable{

        private static final long serialVersionUID = -8631874888098769584L;

        @Column(name="PRODUCT_ID")
        protected Long productId;

        @Column(name="NAME")
        protected String name;

        @Column(name="COUNTRY_CODE")
        protected String countryCode;
        ...
Run Code Online (Sandbox Code Playgroud)

在我获取属性列表并清除之后,然后尝试提交我得到

    ...
    Hibernate: update ATTRIBUTE set PRODUCT_ID=null where PRODUCT_ID=?
    Hibernate: delete from ATTRIBUTE where COUNTRY_CODE=? and …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa

4
推荐指数
2
解决办法
4852
查看次数

标签 统计

hibernate ×3

hibernate-mapping ×1

java ×1

java-ee ×1

jpa ×1

orm ×1

persistence ×1