Results 1 to 5 of 5

Thread: Hibernate error

  1. #1
    Marty is offline Member
    Join Date
    May 2007
    Posts
    38
    Rep Power
    0

    Default Hibernate error

    Hi everybody. I want to know if someone can help me with this problem:
    I am trying to map in hibernate, and when I try to execute mi application it returns me an error in a hbm.xml file.
    I check hibernate in action, links, and so on but I can´t resolve this.

    Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: ar.com.lmi.pojos.Empresacolumn: Emp_Cod (should be mapped with insert="false" update="false")
    Java Code:
    the 2 tables that I try to map are:
    
    CREATE TABLE AREA (
            Area_Cod             int NOT NULL,
            Area_Nivel           int NOT NULL,
            Area_Desc            varchar(50) NULL,
            Emp_Cod              int NOT NULL
     )
    go
     ALTER TABLE AREA
            ADD PRIMARY KEY (Area_Cod, Area_Nivel, Emp_Cod)
    go
    ALTER TABLE AREA
            ADD FOREIGN KEY (Emp_Cod)
                                  REFERENCES EMPRESA
    go
     CREATE TABLE EMPRESA (
            Emp_Cod              int NOT NULL,
            Emp_Desc             varchar(30) NULL,
            Emp_CUIT             varchar(13) NULL,
            Emp_Calle            varchar(30) NULL,
            Emp_Nro              varchar(5) NULL,
            Emp_Piso             varchar(3) NULL,
            Emp_Depto            varchar(3) NULL,
            Emp_Localidad        varchar(30) NULL,
            Emp_CP               varchar(8) NULL,
            Emp_Telefono         varchar(11) NULL,
            Emp_ActDGI           varchar(8) NULL,
            Emp_Actividad        varchar(30) NULL,
            Emp_FirmAnsses       varchar(50) NULL,
            Pcia_Cod             int NULL
     )
    go
     ALTER TABLE EMPRESA
            ADD PRIMARY KEY (Emp_Cod)
    
     
    The xbm.xml are:
     
    <hibernate-mapping package="ar.com.lmi.pojos">
     <class name="Area" table="AREA">
      <composite-id name="areaId" class="AreaId">
       <key-property name="area_Cod" column="Area_Cod"/>
       <key-property name="area_Nivel" column="Area_Nivel"/>
       <key-property name="emp_Cod" column="Emp_Cod"/>
      </composite-id>
      <property name="area_Desc" column="Area_Desc" type="string" not-null="false"/>
      <many-to-one name="emp_Cod" class="Empresa" column="Emp_Cod" update="false" insert="false"/>
     </class>
    </hibernate-mapping>
     
    <hibernate-mapping package="ar.com.lmi.pojos">
     <class name="Empresa" table="EMPRESA">
      <id name="emp_Cod" column="Emp_Cod" type="int">
       <generator class="identity"/>
      </id>
      <property name="emp_Desc" column="Emp_Desc" type="string" not-null="false"/>
      <property name="emp_CUIT" column="Emp_CUIT" type="string" not-null="false"/>
      <property name="emp_Calle" column="Emp_Calle" type="string" not-null="false"/>
      <property name="emp_Nro" column="Emp_Nro" type="string" not-null="false"/>
      <property name="emp_Piso" column="Emp_Piso" type="string" not-null="false"/>
      <property name="emp_Depto" column="Emp_Depto" type="string" not-null="false"/>
      <property name="emp_Localidad" column="Emp_Localidad" type="string" not-null="false"/>
      <property name="emp_CP" column="Emp_CP" type="string" not-null="false"/>
      <property name="emp_Telefono" column="Emp_Telefono" type="string" not-null="false"/>
      <property name="emp_ActDGI" column="Emp_Cod" type="string" not-null="false"/>
      <property name="emp_Actividad" column="Emp_Actividad" type="string" not-null="false"/>
      <property name="emp_FirmAnsses" column="Emp_FirmAnsses" type="string" not-null="false"/>
      <property name="pcia_Cod" column="Pcia_Cod" type="int" not-null="false"/>
      <set name="areas" table="AREA" inverse="true" cascade="all-delete-orphan">
       <key column="Emp_Cod"/>
             <one-to-many class="Area"/>
            </set>
     </class>
    </hibernate-mapping>
     
    pojos:
     
    public class Area implements Serializable {
     private String area_Desc;
      
     /**
      * Constructor
      */
     public Area() {}
     
    //Setters y getters
     
    }
     
    public class AreaId implements Serializable {
     private Integer area_Cod;
     private Integer area_Nivel;
     private Empresa emp_Cod;
     
     /**
      * Constructor
      */
     public AreaId(Integer area_Cod, Integer area_Nivel, Empresa emp_Cod) {
      this.area_Cod = area_Cod;
      this.area_Nivel = area_Nivel;
      this.emp_Cod = emp_Cod;
      
     }
     
    //Setters y getters
    } 
     
    public class Empresa implements Serializable {
     private Integer emp_Cod;
     private String emp_Desc;
     private String emp_CUIT;
     private String emp_Calle;
     private String emp_Nro;
     private String emp_Piso;
     private String emp_Depto;
     private String emp_Localidad;
     private String emp_CP;
     private String emp_Telefono;
     private String emp_ActDGI;
     private String emp_Actividad;
     private String emp_FirmAnsses;
     private Integer pcia_Cod;
     private Set areas = new HashSet();
    
    
     /**
      * Constructor
      */
     public Empresa() {}
     
    //Setters y getters
    }

  2. #2
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    You have emp_code mapped twice.
    In the composite id and in the many to one

  3. #3
    Nick15 is offline Member
    Join Date
    May 2007
    Posts
    38
    Rep Power
    0

    Default

    I would do this: in composite id, I would try to add the options to
    Emp_Cod that indicates insert="false" and theupdate="false".

    here there is a similar problem:
    Hibernate Forums - View topic - Many to Many with composite keys

  4. #4
    pegitha is offline Member
    Join Date
    Apr 2007
    Location
    Indiana
    Posts
    83
    Rep Power
    0

    Default

    In your link to the forum,they have their bidirectional mapping inside the <composite id> try that.
    I have never had a lot of luck with composite ids, but you do definitely have it mapped twice as the error says.

  5. #5
    Bala123 is offline Member
    Join Date
    Jun 2008
    Posts
    1
    Rep Power
    0

    Default Hibernate error for bala123

    Hi

    I am new to Hibernate.
    I am trying to insert tha data in Oracle9i database through Hibernate3.1 by using the MyEclipse6 IDE.

    error is:
    "Exception in thread "main" org.hibernate.MappingException: Unknown
    entity:org.hiber.test.DepthomeId "

    Could you please check it and send the solution.

    hbm.cfg.xml file
    -----------------------
    <hibernate-configuration>

    <session-factory name="sessionfactory">
    <property name="connection.username">scott</property>
    <property name="connection.url">
    jdbc:oracle:thin:@localhost:1521:OraBala
    </property>
    <property name="dialect">
    org.hibernate.dialect.Oracle9Dialect
    </property>
    <property name="myeclipse.connection.profile">
    BalaHiber
    </property>
    <property name="connection.password">tiger</property>
    <property name="connection.driver_class">
    oracle.jdbc.driver.OracleDriver
    </property>

    <mapping resource="org/hiber/test/Depthome.hbm.xml" />

    </session-factory>

    </hibernate-configuration>
    -----------------------------------------------------------------

    depthome.hbm.xml file
    ------------------------
    <hibernate-mapping>
    <class name="org.hiber.test.Depthome" table="DEPTHOME" schema="SCOTT">
    <composite-id name="id" class="org.hiber.test.DepthomeId">
    <key-property name="dno" type="java.lang.Long">
    <column name="DNO" precision="2" scale="0" />
    </key-property>
    <key-property name="dname" type="java.lang.String">
    <column name="DNAME" length="10" />
    </key-property>
    <key-property name="loc" type="java.lang.String">
    <column name="LOC" length="15" />
    </key-property>
    </composite-id>
    </class>
    </hibernate-mapping>
    ----------------------------------------------------------



    POJO Class for DepthomeId class file
    ---------------------------------------

    package org.hiber.test;

    /**
    * DepthomeId entity.
    *
    * @author MyEclipse Persistence Tools
    */

    public class DepthomeId implements java.io.Serializable {

    // Fields

    private Long dno;
    private String dname;
    private String loc;

    // Constructors

    /** default constructor */
    public DepthomeId() {
    }

    /** full constructor */
    public DepthomeId(Long dno, String dname, String loc) {
    this.dno = dno;
    this.dname = dname;
    this.loc = loc;
    }

    // Property accessors

    public Long getDno() {
    return this.dno;
    }

    public void setDno(Long dno) {
    this.dno = dno;
    }

    public String getDname() {
    return this.dname;
    }

    public void setDname(String dname) {
    this.dname = dname;
    }

    public String getLoc() {
    return this.loc;
    }

    public void setLoc(String loc) {
    this.loc = loc;
    }

    public boolean equals(Object other) {
    if ((this == other))
    return true;
    if ((other == null))
    return false;
    if (!(other instanceof DepthomeId))
    return false;
    DepthomeId castOther = (DepthomeId) other;

    return ((this.getDno() == castOther.getDno()) || (this.getDno() != null
    && castOther.getDno() != null && this.getDno().equals(
    castOther.getDno())))
    && ((this.getDname() == castOther.getDname()) || (this
    .getDname() != null
    && castOther.getDname() != null && this.getDname()
    .equals(castOther.getDname())))
    && ((this.getLoc() == castOther.getLoc()) || (this.getLoc() != null
    && castOther.getLoc() != null && this.getLoc().equals(
    castOther.getLoc())));
    }

    public int hashCode() {
    int result = 17;

    result = 37 * result
    + (getDno() == null ? 0 : this.getDno().hashCode());
    result = 37 * result
    + (getDname() == null ? 0 : this.getDname().hashCode());
    result = 37 * result
    + (getLoc() == null ? 0 : this.getLoc().hashCode());
    return result;
    }

    }
    -------------------------------------------------------------

    Hibernate class of a Hibappone.java file
    ------------------------------------------->

    package org.hiber.test;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.*;
    import org.hibernate.*;

    public class HibAppOne {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    Configuration configuration=new Configuration();
    configuration.configure();
    SessionFactory sessionFactory=configuration.buildSessionFactory() ;
    Session session=sessionFactory.openSession();

    // Session session=org.hiber.test.OraSF.currentSession();
    Transaction transaction=session.beginTransaction();
    System.out.println("Up to transaction was created");

    //Depthome depthome=new Depthome();
    DepthomeId depthomeId=new DepthomeId();


    depthomeId.setDno(new Long(1));
    depthomeId.setDname("Bali");
    depthomeId.setLoc("Vgya");

    session.save(depthomeId);

    transaction.commit();
    session.close();


    }

    }

    Let me know any solution for this.

    Bala

Similar Threads

  1. Hibernate, help me
    By Nick15 in forum JDBC
    Replies: 2
    Last Post: 06-05-2008, 04:39 PM
  2. Replies: 2
    Last Post: 06-30-2007, 04:01 PM
  3. Hibernate Error
    By yuchuang in forum JDBC
    Replies: 2
    Last Post: 05-15-2007, 11:24 AM
  4. Replies: 3
    Last Post: 05-14-2007, 06:10 PM
  5. Hibernate
    By Shuru in forum JDBC
    Replies: 2
    Last Post: 05-09-2007, 06:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •