Hibernate version:
2.1.6
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="org.rhavyn.communities.services.core">
<class name="User" table="users">
<id name="id">
<column name="user_id" sql-type="char(32)"/>
<generator class="uuid.hex"/>
</id>
<property name="username" access="field" update="false" not-null="true"
unique="true" length="20"/>
<component name="password" class="Password">
<property name="hashedPassword" access="field">
<column name="password" not-null="true" sql-type="char(32)"/>
</property>
</component>
<property name="admin" not-null="true" column="is_admin"/>
<property name="firstName" not-null="true" column="first_name" length="50"/>
<property name="lastName" not-null="true" column="last_name" length="50"/>
<property name="email" not-null="true" length="100"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
MySQL 4.0.x and Postgres 7.3.x
Debug level Hibernate log excerpt:
N/A
Hello,
In my application I have an entity mapped as above. There is certain business logic and security constraints which need to be validated before an update can occur. For example, the admin field should only be updatable by someone who is currently an admin and whenever the email field is updated, a confirmation email needs to be sent to the new address. What I was trying to avoid was to have to select a copy of the object out of the database and then hand comparing the fields. I looked into making User abstract, not provided setters for email and admin, and providing a concrete subclass in the business layer which would have access to those fields. That feels like a dirty solution to me, though, but I am willing to hear reasons why it isn't. Is there a generally accepted method of mapping something like that in the Hibernate community?
Thanks in advance.