-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with hibernate mapping
PostPosted: Mon Jan 22, 2007 10:07 am 
Newbie

Joined: Mon Jan 22, 2007 9:47 am
Posts: 1
Hi, I'm new to Hibernate and I am trying to map a simple database.

I've used the Hibernate Synchronizer plugin for eclipse to generate the mapping files, but I keep getting this exception when I run the program:

Code:
Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: com.opus.hibernate.Atividade column: id_projeto (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:605)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:627)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:645)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:420)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1099)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1284)
   at com.opus.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:101)
   at com.opus.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:88)
   at com.opus.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:79)
   at com.opus.hibernate.Hibernate_Test.main(Hibernate_Test.java:14)


The .hbm.xml files that are the cause of the above exception are:

atividade.hbm.xml:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.opus.hibernate">
   <class
      name="Atividade"
      table="atividade"
   >
      <meta attribute="sync-DAO">true</meta>
      <id
         name="Id"
         type="java.lang.Long"
         column="id_atividade"
      >
         <generator class="sequence"/>
      </id>

      <property
         name="NmAtividade"
         column="nm_atividade"
         type="string"
         not-null="true"
         length="255"
      />
      <property
         name="NumHoras"
         column="num_horas"
         type="java.lang.Long"
         not-null="true"
         length="4"
      />
      <property
         name="NumMinutos"
         column="num_minutos"
         type="java.lang.Long"
         not-null="true"
         length="4"
      />
      <property
         name="DtAtividade"
         column="dt_atividade"
         type="date"
         not-null="true"
         length="4"
      />
      <many-to-one
         name="IdFase"
         class="FaseProjeto"
         not-null="true"
      >
      </many-to-one>
      <many-to-one
         name="IdProjeto"
         column="id_projeto"
         class="Projeto"
         not-null="true"
      >
      </many-to-one>
      <many-to-one
         name="IdUsuario"
         column="id_usuario"
         class="Usuario"
         not-null="true"
      >
      </many-to-one>


   </class>   
</hibernate-mapping>


FaseProjeto.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "/usr/local/hibernate-3.2/src/org/hibernate/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.opus.hibernate">
   <class
      name="FaseProjeto"
      table="fase_projeto"
   >
      <meta attribute="sync-DAO">true</meta>
      <composite-id name="Id" class="FaseProjetoPK">
         <key-property
            name="IdFase"
            column="id_fase"
            type="java.lang.Long"
         />
         <key-many-to-one
            name="IdProjeto"
            class="Projeto"
            column="id_projeto"
         />
      </composite-id>

      <property
         name="NmFase"
         column="nm_fase"
         type="string"
         not-null="false"
         length="30"
      />

   </class>   
</hibernate-mapping>


I believe that the problem is that I am trying to get a foreign key from the FaseProjeto table, but because that key is a composite-id, then I must create 2 columns referencing both keys form FaseProjeto instead of just the key that I want (id_fase).

The problem is that I want to select have just id_fase as a foreign key from FaseProjeto and not id_fase and id_projeto. Is there a way to select only id_fase to be my foreign key?

Thanks,
Komg

PS: I am using Hibernate 3.2


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.