By now I figured out that what I really want to do is having
one-to-many for user -> privilege, and a many-to-one for
privilege->user, pretty standard case I would assume, however I get
some really weird errors with this mapping file:
<hibernate-mapping>
<class name="net.snyke.tmm.Privilege" table="privilege">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="read" column="isRead"/>
<property name="write" column="isWrite"/>
<many-to-one name="user" class="net.snyke.tmm.UserAccount"
column="user" not-null="true" />
<many-to-one name="account"
class="net.snyke.tmm.FinancialAccount" column="account" not-null="true"
/>
</class>
<class name="net.snyke.tmm.UserAccount" table="users">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="password"/>
<bag name="userPrivileges"
inverse="true"
lazy="false"
cascade="all">
<key column="user_privileges"/>
<one-to-many class="net.snyke.tmm.Privilege"/>
</bag>
</class>
<class name="net.snyke.tmm.FinancialAccount" table="accounts">
<id name="id" column="id">
<generator class="native"/>
</id>
</class>
</hibernate-mapping>
namely this:
17:16:10,052 INFO Configuration:1286 - configuring from resource:
/hibernate.cfg.xml
17:16:10,052 INFO Configuration:1263 - Configuration resource:
/hibernate.cfg.xml
17:16:10,056 INFO Configuration:468 - Reading mappings from resource:
mapping.hbm.xml
17:16:10,144 INFO DriverManagerConnectionProvider:147 - cleaning up
connection pool: jdbc:mysql://localhost/test
17:16:10,153 INFO Mappings:137 - duplicate import:
net.snyke.tmm.Privilege->net.snyke.tmm.Privilege
17:16:10,153 INFO Mappings:137 - duplicate import:
net.snyke.tmm.Privilege->Privilege
17:16:10,154 INFO HbmBinder:265 - Mapping class:
net.snyke.tmm.Privilege -> privilege
%%%% Error Creating HibernateSessionFactory %%%%
org.hibernate.MappingException: Could not read mappings from resource:
mapping.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Config uration.java:484)
at
org.hibernate.cfg.Configuration.parseMappingElemen t(Configuration.java:1443)
at
org.hibernate.cfg.Configuration.parseSessionFactor y(Configuration.java:1411)
at
org.hibernate.cfg.Configuration.doConfigure(Config uration.java:1392)
at
org.hibernate.cfg.Configuration.doConfigure(Config uration.java:136

at org.hibernate.cfg.Configuration.configure(Configur ation.java:128

at
net.snyke.tmm.persister.HibernateSessionFactory.in itSessionFactory(HibernateSessionFactory.java:9

at
net.snyke.tmm.persister.HibernateSessionFactory.ge tInstance(HibernateSessionFactory.java:54)
at
net.snyke.tmm.TestUserAccount.testPersistence(Test UserAccount.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154 )
at junit.framework.TestCase.runBare(TestCase.java:127 )
at junit.framework.TestResult$1.protect(TestResult.ja va:106)
at junit.framework.TestResult.runProtected(TestResult .java:124)
at junit.framework.TestResult.run(TestResult.java:109 )
at junit.framework.TestCase.run(TestCase.java:11

at junit.framework.TestSuite.runTest(TestSuite.java:2 0

at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:47

at
org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.DuplicateMappingException: Duplicate
class/entity mapping net.snyke.tmm.Privilege
at org.hibernate.cfg.Mappings.addClass(Mappings.java: 117)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.jav a:110)
at org.hibernate.cfg.Configuration.add(Configuration. java:385)
at
org.hibernate.cfg.Configuration.addInputStream(Con figuration.java:426)
at org.hibernate.cfg.Configuration.addResource(Config uration.java:481)
... 23 more
Any idea?