Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Mapping Exception : Repeated column in mapping for entity

There is a mapping exception for a particular entity. Cant figure out from where the problem is arising. I checked all the mappings 3 times from start to end. Still i am getting a Mapping Exception.

Email to employee is mapped only once. but still it is reporting the error repeated mapping

Error is:

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

Email 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 = intEmailID;
    }

    public String getStrEmailName() {
        return strEmailName;
    }

    public void setStrEmailName(String strEmailName) {
        this.strEmailName = strEmailName;
    }

    public EmailType getEmailType() {
        return emailType;
    }

    public void setEmailType(EmailType emailType) {
        this.emailType = emailType;
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

}

email.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
        'http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd'>


<hibernate-mapping package="com.cluster.entity" >
    <class name="Email" table="EMAIL">

        <id name="intEmailID" column="EMAIL_ID"> 
            <generator class="sequence">
                <param name="sequence">EMAIL_ID_SEQ</param>
            </generator>
        </id>

        <property name="strEmailName" column = "EMAIL_NAME"/>

        <many-to-one name="employee" column="EMPLOYEE_ID" not-null = "true" class = "Employee"/>

        <many-to-one name="emailType" column="EMAIL_TYPE_ID" not-null = "true" class = "EmailType"/>

    </class>

</hibernate-mapping>

Related Script

CREATE TABLE EMPLOYEE
(
  EMPLOYEE_ID      NUMBER                       NOT NULL,
  FIRSTNAME        VARCHAR2(20 BYTE)            NOT NULL,
  LASTNAME         VARCHAR2(20 BYTE)            NOT NULL,
  DATE_OF_BIRTH    VARCHAR2(20 BYTE)            NOT NULL,
  SALARY           VARCHAR2(10 BYTE)            NOT NULL,
  DEPARTMENT_ID    NUMBER                       NOT NULL
);


CREATE TABLE EMAIL
(
 EMAIL_ID              NUMBER              NOT NULL,
 EMAIL_NAME            VARCHAR2(40 BYTE)   NOT NULL,
 EMPLOYEE_ID           NUMBER              NOT NULL,
 EMAIL_TYPE_ID         NUMBER              NOT NULL
);


CREATE TABLE EMAIL_TYPE
(
 EMAIL_TYPE_ID         NUMBER              NOT NULL,
 EMAIL_TYPE_NAME       VARCHAR2(40 BYTE)   NOT NULL
);


ALTER TABLE EMPLOYEE ADD 
(
 CONSTRAINT PK_EMPLOYEE_ID
 PRIMARY KEY (EMPLOYEE_ID)
);

ALTER TABLE EMAIL_TYPE ADD 
(
 CONSTRAINT PK_EMAIL_TYPE_ID
 PRIMARY KEY (EMAIL_TYPE_ID)
);

ALTER TABLE EMAIL ADD
(
 CONSTRAINT PK_EMAIL_ID
 PRIMARY KEY (EMAIL_ID)
);

ALTER TABLE EMAIL ADD
( 
 CONSTRAINT FK_EMAIL_EMPLOYEE_ID
 FOREIGN KEY (EMPLOYEE_ID)
 REFERENCES EMPLOYEE (EMPLOYEE_ID)
);

ALTER TABLE EMAIL ADD
( 
 CONSTRAINT FK_EMAIL_EMAIL_TYPE_ID
 FOREIGN KEY (EMAIL_TYPE_ID)
 REFERENCES EMAIL_TYPE (EMAIL_TYPE_ID)
);

Email to employee is mapped only once. but still it is reporting the error repeated mapping

like image 899
bali208 Avatar asked Feb 21 '12 16:02

bali208


People also ask

What is referencedColumnName in @JoinColumn hibernate?

The usage of the isbn as the foreign key requires an additional @JoinColumn annotation. The referencedColumnName attribute tells Hibernate the name of the database column it shall use as the foreign key.

What is @primarykeyjoincolumn?

It is used to join the primary table of an entity subclass in the JOINED mapping strategy to the primary table of its superclass; it is used within a SecondaryTable annotation to join a secondary table to a primary table; and it may be used in a OneToOne mapping in which the primary key of the referencing entity is ...

What is @onetomany Mappedby?

Simply put, one-to-many mapping means that one row in a table is mapped to multiple rows in another table. Let's look at the following entity-relationship diagram to see a one-to-many association: For this example, we'll implement a cart system where we have a table for each cart and another table for each item.

What is @mapsid?

Use Map IDs. Paid feature: Functionality accessed by adding a map ID triggers a map load charged against the Dynamic Maps SKU for Android and iOS. See Google Maps Billing for more information. A map ID is an identifier that's associated with a specific map style or feature.


1 Answers

have you set the collection in Employee as inverse?

<bag name="emails" inverse="true">
  <key column="EMPLOYEE_ID" not-null="true">
  ...
</bag>
like image 120
Firo Avatar answered Sep 23 '22 15:09

Firo