-->
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: Can Insert new rows, but Can't update the rows. Please Help!
PostPosted: Fri Nov 17, 2006 1:47 pm 
Newbie

Joined: Tue Oct 31, 2006 4:06 pm
Posts: 7
The mapping is a simple 1-to-many relationships. I was able to insert new rows, but I can't update them. The program doesn't complain, nor does it throw any exceptions. I turned on show_sql to true, and I don't see any update statements. This is a simple program, but not sure why it doesn't work.

Thanks in advance.

public class Status implements Serializable
{
private String id;
private String status;

... With setters and getters
}


The mapping file is:

<class
name="Status"
table="status"
lazy="false"
>
<cache usage="nonstrict-read-write" />

<id
name="id"
column="id"
type="java.lang.String"
unsaved-value="null"
>
<generator class="uuid.hex">
</generator>
</id>

<property
name="status"
type="java.lang.String"
update="true"
insert="true"
column="status"
unique="false"
/>



public class Work implements Serializable
{
private String id;
private User user;
private Status status;

... With setters and getters
}


<class
name="Work"
table="work"
lazy="true"
>
<cache usage="read-write" />

<id
name="id"
column="id"
type="java.lang.String"
unsaved-value="null"
>
<generator class="uuid.hex">
</generator>
</id>

<many-to-one
name="user"
class="User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="user_id"
not-null="false"
/>

<many-to-one
name="status"
class="Status"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="status_id"
not-null="true"
/>

</class>


In another class:

Work work = workManager.getWork(workId);
Status status = work.getStatus();
status.setId("2");
status.setStatus("pending");

Session session = sessionFactory.getCurrentSession();

session.beginTransaction();

session.lock(work, LockMode.NONE);
session.saveOrUpdate(work);
session.getTransaction().commit();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 4:16 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
You have cascade="none" on the many-to-one from Work to Status. Change that to (for example) cascade="save-update,lock".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 4:22 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Also, you have a UUID generator for the Status' identifier, yet you explicitly set the id property. Whazzup with that?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 4:23 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
The work you get from your workManager.getWork() is new or retrieved from the db ?

In your case, I guess the cascade="none" and the fact you're only trying to reattach Work, but not Status could be the reason of your problem.

Are your objects detached in your code or is the session related to them still active ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 2:52 pm 
Newbie

Joined: Tue Oct 31, 2006 4:06 pm
Posts: 7
It's my mistake to try to set the ID in the persistent object.

Thanks for the help.


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.