-->
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: deleting record using session.get()
PostPosted: Tue May 29, 2007 1:52 pm 
Newbie

Joined: Sat Feb 24, 2007 4:58 am
Posts: 4
Hi everybody,

I have an issue,
I want to delete a record from a table.


Actually I want to delete the record from USER_PROJECTS table, the columns are
project_id -- f.k to Project table, user_name-- f.k to User table.

I have the POJOs like

UserProjects.java

UserPrjParam param,
Project project,
User userName

---------------------

Project.java

projectId,
prjDesc
.
.
.
.

-------------------------

User.java

userName,
phoneNo,
.
.
.
.

---------------------------------

UserPrjParam .java

userName,
projectId


-----------------------------------

I am trying to delete record by giving like

UserProjects up =(UserProjects) session.get(UserProjects.class, "here I am getting problem")

If I have any specific value in the POJO i can mention. Bu I have only relation.

So I have tried this one like.

Project p = (Project) session.get(Project.class, projectId);
UserProjects up =(UserProjects) session.get(UserProjects.class, p);

But this is throwing error like "entity not found".......



Can any one please help me on this issue.



Thanks in advance


[/b]

_________________
Regards
Manickaraj


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 5:48 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Well you can delete the entry from the link table (the USER_PROJECTS) table this way.

user.getProjects().remove(project);
project.getUsers().remove(user);

session.update(user);

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject: Re: delete record using session.get()
PostPosted: Wed May 30, 2007 2:56 am 
Newbie

Joined: Sat Feb 24, 2007 4:58 am
Posts: 4
Hey,

I got ur point. But this won't be helpful to remove the entry in USER_PROJECTS. Moreover u r saying session.update(user), this will update the USER table.

But I need to delete the record from USER_PROJECTS table. Do i need to go for any delete query.









I expect ur reply



Thanks

_________________
Regards
Manickaraj


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 4:05 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

I think this is not your prblem. but i have to comment on this line

Code:
Project p = (Project) session.get(Project.class, projectId);
UserProjects up =(UserProjects) session.get(UserProjects.class, p);



here session.get() is session.get(Class clazz,Serializable id).

clazz is ok

but id it is a serializable object.
Normally if you have a id not composite-id the serializable id may string parameter. but in composite-id situation you have to mention what is the class for composite-id

Code:
<composite-id class="Test"> .... </composite-id>


in such condition you can pass a named Object to get method to load entity.



Amila

(Don't forget to rate if helps)


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.