bridget.mertens wrote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelpHibernate version:3.0 Mapping documents:Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Name and version of the database you are using:MySQL 3.1.8The generated SQL (show_sql=true):Debug level Hibernate log excerpt:In the Hibernate documentation it is implied that a table will be mapped to by only one class. Is it possible to have one table mapped to by more than one class? If so are there any locking implications?
This is simplified mapping from our current project it is working just fine. About locking, so far we had no issues, problem or any kind of restrictions and etc ....
Map1:
Code:
<class name="Account" table="account">
<id name="accountId" column="ACCOUNT_ID" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="balance" column="BALANCE" />
</class>
Map2:
Code:
<class name="SearchAccount" table="account">
<id name="accountId" column="ACCOUNT_ID" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="balance" column="BALANCE" />
<one-to-one name="account" class="AjDataAccount" />
<set name="customers" lazy="true" order-by="ACCOUNT_ID">
<key column="ACCOUNT_ID" />
<one-to-many class="customer" />
</set>
</class>
We used such an approach in few areas of our app. Actually everywhere where that was used one class was user for read-only data other for all of the rest. We have some cases where we had implemented more then two classes mapped on the same table for different buisiness logic to improve performance. Be careful to use that it can cause code maintenance issues later.