I'm using hibernate 2.1 and it works fine. But now, I try to map an existing table from an existing database.
Voici la structure de ma table :
here is the structure of the FOO table :
Code:
create table FOO (
id1 smallint not null,
id2 smallint not null,
id3 char(2) not null,
id4 char(3) not null,
primary key (id1, id2, id3, id4)
)
and the mapping file
Code:
<hibernate-mapping>
<class name="mypackage.Foo" table="FOO">
<composite-id name="compId" class="mypackage.FooCompositeID>
<key-property name="id1" column="id1" type="int"/>
<key-property name="id2" column="id2" type="int"/>
<key-property name="id3" column="id3" type="string"/>
<key-property name="id4" column="id4" type="string"/>
</composite-id>
</class>
</hibernate-mapping>
It returns this error :
Code:
Caused by: java.lang.RuntimeException: Exception building SessionFactory: Error reading resource: monpaquetage/hibernate/Toto.hbm.xml
at monpaquetage.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:45)
... 33 more
Caused by: net.sf.hibernate.MappingException: Error reading resource: monpaquetage/hibernate/Toto.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:318)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:976)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:928)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:871)
at monpaquetage.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:42)
... 33 more
Caused by: net.sf.hibernate.MappingException: duplicate import: MapToto
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1229)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:285)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:315)
... 37 more
The class "FooCompositeID" implements Serializable and overrides hashCode() and equals()