-->
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.  [ 5 posts ] 
Author Message
 Post subject: read-only while update
PostPosted: Sun Nov 02, 2003 9:26 pm 
Beginner
Beginner

Joined: Sat Nov 01, 2003 6:14 am
Posts: 30
i have experienced jcs for hibernate before

i read the doc that "read-only" has more performance than"read-write"

but my data will be edited , may dur a long time

as my experience , if i update one piece of data , it's all relations must be "read-write" , otherwise , exception will welcome me

i wonder there is a way , i use "read-only" cache , and in runtime , i update the data then refresh the cache( maybe clear the cache) coded in my project?

can i handle this in "read-only" env?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2003 9:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
as my experience , if i update one piece of data , it's all relations must be "read-write" , otherwise , exception will welcome me


Not true. Perhaps you should explain this problem a bit better. Is it because you enable cascade="save-update"?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2003 10:07 pm 
Beginner
Beginner

Joined: Sat Nov 01, 2003 6:14 am
Posts: 30
gavin wrote:
Quote:
as my experience , if i update one piece of data , it's all relations must be "read-write" , otherwise , exception will welcome me


Not true. Perhaps you should explain this problem a bit better. Is it because you enable cascade="save-update"?


ah ha , gavin always quick and kind answer :)

en , let me try to describ

as i said in another post(http://forum.hibernate.org/viewtopic.ph ... 66#2176666) , i have a ForumUser object

theForumUser 's cache is "read-write" , but one of it's relations Face as another object is "read-only" , the many-to-one schema is :

Code:
<many-to-one
            name="face"
            class="net.magician.business.views.Pic"
            cascade="all"
            outer-join="true"
            update="true"
            insert="true"
            column="faceID"
            not-null="false"
        />


so , if i update forumuser like above , application will throw exception

but , if i change the cache of Pic to "read-write" , everything is ok

maybe something wrong in my schema


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2003 10:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, the reason for that is that you have cascade="all". Now, for a read-only class, cascade="all" makes absolutely no sense - it means that it is possible to delete this object of class. In your case, I think that what is happening is that the update is cascaded to the child, which is an error, because the child is read-only.

Now, this -does- raise an interesting point. It is not unreasonable to have

Code:
<class name="Bar" immutable="true">
<cache usage="read-only"/>
</class>

<class name="Foo">
<many-to-one name="bar" class="Bar" cascade="save-update"/>
<class/>


Because you want new instances of Bar to be saved by cascade, but because they are immutable, an update is unnecessary.

Currently, Hibernate would throw an exception in this case. This is suboptimal, I think. You should be able to persist immutable objects by cascade. What we need is for update() to degrade gracefully to lock() in the case of an immutable object.


Anyway, regarding your problem, try usage="nonstrict-read-write", if performance is bothering you - though I don't particularly see how it could be such a big difference.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2003 10:31 pm 
Beginner
Beginner

Joined: Sat Nov 01, 2003 6:14 am
Posts: 30
gavin wrote:
Yes, the reason for that is that you have cascade="all". Now, for a read-only class, cascade="all" makes absolutely no sense - it means that it is possible to delete this object of class. In your case, I think that what is happening is that the update is cascaded to the child, which is an error, because the child is read-only.

Now, this -does- raise an interesting point. It is not unreasonable to have

Code:
<class name="Bar" immutable="true">
<cache usage="read-only"/>
</class>

<class name="Foo">
<many-to-one name="bar" class="Bar" cascade="save-update"/>
<class/>


Because you want new instances of Bar to be saved by cascade, but because they are immutable, an update is unnecessary.

Currently, Hibernate would throw an exception in this case. This is suboptimal, I think. You should be able to persist immutable objects by cascade. What we need is for update() to degrade gracefully to lock() in the case of an immutable object.


Anyway, regarding your problem, try usage="nonstrict-read-write", if performance is bothering you - though I don't particularly see how it could be such a big difference.


thanks for your particular reply!

i exactly konw what i should do next.

the way , i use xdoclet to generate the mapping-file , but it doesn't support the "nonstrict-read-write" property

maybe we should advice xdoclet to update their product :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.