Hi,
I have a single POJO class called 'User' that is mapped to two tables (USERS and USER_ROLES)
When I invoke session.save(user) it gives the following error:
net.sf.hibernate.MappingException: duplicate import: User
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:1243)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:285)
Is there a specific way to define the *.hbm.xml files when the same bean is mapped to more than one table.
I have defined two hbm.xml files one for user table and one for role table and both refer to, obviously, the same POJO class.
//user.hbm.xml
<hibernate-mapping package="com.proj.beans">
<class name="User" table="USERS">
<id name="userId" column="USERNAME">
<generator class="assigned" />
</id>
<property name="password" column="PASSWORD"/>
<property name="repId" column="SALESREPID"/>
</class>
</hibernate-mapping>
//userrole.hbm.xml
<hibernate-mapping package="com.proj.beans">
<class name="User" table="USER_ROLES">
<id name="userId" column="USERNAME">
<generator class="assigned"/>
</id>
<property name="roleName" column="ROLENAME"/>
</class>
</hibernate-mapping>
and I do the following in my configuaration:
cfg.addInputStream(this.getClass().
getClassLoader().getResourceAsStream("User.hbm.xml"));
cfg.addInputStream(this.getClass().
getClassLoader().getResourceAsStream("UserRole.hbm.xml"));
Any help will be much appreciated.
Thanks,
Jeelani
|