Hi, I try to use a 1:N read-only immutable mapping.
The class LoginUser has a method getAuthorities() which returns an immutable array of Authority objects. I tried several mapping settings.
First I set the mutable flag to false and the cache usage to read-only in the target class Authorities. But that had no effect to the update mechanism. Hibernate tried to update the Authorities when saving LoginUser and it results in a database error.
Next I tried to set the cache usage in the LoginUser mapping. But then I got an exception from hibernate, that i tried to save a read-only cache.
After that i thought declaring the getter as mutable="false" will solve the problem, but with this version i got the following error.
Is it impossible to prevent hibernate from updating an array?
Thanks for your help!
Hibernate version:
3.0.5
Mapping documents:
<hibernate-mapping default-lazy="false">
<class name="LoginUser" table="login_user">
....
<array name="authorities"
cascade="none"
mutable="true">
<key column="loginuser_id" />
<index column="the_index" />
<one-to-many class="Authorities"
/>
</array>
....
</class>
</hibernate-mapping>
<hibernate-mapping default-lazy="false" >
<class name="Authorities" mutable="false">
<subselect>
select distinct r.name, l.id as loginuser_id, r.the_index
from right r, User_Base_Data u, Login_User l
where r.node_id=u.rights_node_id AND u.id=l.user_base_data_id
</subselect>
<cache usage="read-only"/>
<synchronize table="login_user"/>
<synchronize table="user_base_data"/>
<synchronize table="rights_node"/>
<synchronize table="right"/>
<id name="authority"
column="name"
type="string" >
<generator class="native" />
</id>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
Caused by: org.xml.sax.SAXParseException: Attribute "mutable" must be declared for element type "array".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
|