-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Immutable array problem
PostPosted: Wed Mar 01, 2006 6:50 am 
Newbie

Joined: Wed Feb 15, 2006 8:40 am
Posts: 7
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)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 8:52 am 
Newbie

Joined: Wed Feb 15, 2006 8:40 am
Posts: 7
I did a workaround. When using a set instead of an array then variant 1 works. So I use a set and convert it in the original getter method to an array. But nevertheless it would be interesting if an array canĀ“t be immutable.

Thx,
Andi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.