Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-10-2007, 06:04 PM
Member
 
Join Date: May 2007
Posts: 38
Marty is on a distinguished road
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")
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 }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-10-2007, 06:14 PM
orchid's Avatar
Member
 
Join Date: Apr 2007
Location: Midwest
Posts: 60
orchid is on a distinguished road
You have emp_code mapped twice.
In the composite id and in the many to one
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-10-2007, 06:45 PM
Member
 
Join Date: May 2007
Posts: 39
Nick15 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-10-2007, 07:14 PM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-04-2008, 06:03 AM
Member
 
Join Date: Jun 2008
Posts: 1
Bala123 is on a distinguished road
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
entityrg.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">
jdbcracle: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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hibernate, help me Nick15 Database 2 06-05-2008 04:39 PM
org.hibernate.ejb.Version <clinit> INFO: Hibernate EntityManager 3.2.0.CR1 Heather Database 2 06-30-2007 04:01 PM
Hibernate Error yuchuang Database 2 05-15-2007 11:24 AM
error in JBoss with hibernate, EJB3 and postgres Nick15 Eclipse 3 05-14-2007 06:10 PM
Hibernate Shuru Database 2 05-09-2007 06:39 PM


All times are GMT +3. The time now is 07:06 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org