-->
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.  [ 4 posts ] 
Author Message
 Post subject: PROBLEM: object references an unsaved transient instance
PostPosted: Mon Feb 20, 2006 1:20 pm 
Newbie

Joined: Fri Jan 20, 2006 12:48 pm
Posts: 6
I have to simpe functions, and on button click I get exception:"object references an unsaved transient instance - save the transient instance before flushing: Accordia.DataLayer.Configuration.Workspace"

Relationship betwen AppUser and Workspace is bi_directional, cascade=all, inverse=true,...

I cant' get this DONE!
I tried with all version of lock and everithing else.
I would bee happy if some have the answer.

private AppUser GetUser(int id)
{
ISession sess = SessionManager.getSession();
if (!sess.IsConnected)
sess.Reconnect();

AppUser user = (AppUser)sess.Get(typeof(AppUser), id);
//
//
//user.workspaceId, workspaceId is a object of class Workspace and PK from table workspace is a FK in table app_user
//
sess.Close();
return user;
}
private void button1_Click(object sender, EventArgs e)
{


ISession sess = SessionManager.getSession();
if (!sess.IsConnected)
sess.Reconnect();

AppUser ent = GetUser(7);

sess.Lock(ent, LockMode.UpgradeNoWait);
ent.endDate = DateTime.Now;

try
{
sess.SaveOrUpdate(ent);
sess.Flush();
}
catch (Exception ex)
{
sess.Close();
ex = null;
}
sess.Close();

}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 11:53 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The problem is probably 'inverse="true"'. You've put it on the set in AppUser? inverse="true" means that this side of the relationship does NOT manage the relationship. If you will always be saving Workspaces by putting them into AppUser's collection of Workspaces, then you want inverse="false".


Top
 Profile  
 
 Post subject: Thanks for reply, but...
PostPosted: Tue Feb 21, 2006 7:58 am 
Newbie

Joined: Fri Jan 20, 2006 12:48 pm
Posts: 6
First of all, thanks.
You are right, but I need a parent referece and a references on all children, parts of maping files are:

Workspace: <bag name="AppUserList" inverse="true" table="app_user" lazy="true" cascade="all" >
<key column="workspace_id" />
<one-to-many class="Accordia.DataLayer.Configuration.AppUser,DataLayer" />
</bag>

AppUser: <many-to-one name="workspaceId" column="workspace_id" class="Accordia.DataLayer.Configuration.Workspace, DataLayer" />

The idea is to read user (witch have a referece to parent) in one session, than close that session, at this time user (from the code from last post) is detach, then open second session in the second session I bring that user (let say that a as a function return, like a code form last post), and that make some minor changes and THAN simply update user. This is a most common thing to do, I need that all the time, I tried with a sess.Lock(...) but it constantly saying the a workspace (parent of a user) is transistient object and that need to be saved, that is unacceptable for me.

Note: My english is not so goog, I hope that you understand what I'm trying to say.


Top
 Profile  
 
 Post subject: Problem NO MORE
PostPosted: Tue Feb 21, 2006 10:36 am 
Newbie

Joined: Fri Jan 20, 2006 12:48 pm
Posts: 6
I have found my problem, stupid litle thing :)

unsaved-value="any"


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