-->
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: Help Needed in Update Operation
PostPosted: Tue Jan 08, 2008 2:47 am 
Newbie

Joined: Tue Jan 08, 2008 2:20 am
Posts: 4
Hi,
I am new to Hibernate Development.I am using hibernate3.jar for development.
I an idea to pereform update operation.
The table structure is below.

TABLE USER

Column Name ID Pk Null? Data Type
USER_KEY 1 1 N NUMBER (9)
USER_ID 2 Y VARCHAR2 (3)
USER_NAME 3 Y VARCHAR2 (30)
USER_ADDRESS 4 Y VARCHAR2 (30)
USER_VALUE 5 Y VARCHAR2 (100)

I had prepared the cfc & mapping xml for these table.

I need to perform update only the user_name only using the user_id.
Since user_id is not the primary key,
How can i perform the update operation.

Please comments


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 11:49 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 7:43 am
Posts: 31
Location: León (Spain)
Either user an HQL update like:

"update User u set u.userName = theUserName where u.userId = theUserId"

Or use an HQL query to retrieve the row by USER_ID, and then update the object. You should ensure that USER_IDs are unique:

Query q = session.createQuery("from User u where u.userId = theId");
User theUser = (User)q.uniqueResult();
theUser.setUserName(theName);
session.update(theUser);

If not unique, the only way I know is to programatically select the row from the list of possible results:

List users = q.list();
Iterator it = users.iterator();
while (it.hasNext()) {
// do whatever you can
}

_________________
Please rate...

Expert on Hibernate errors... I've had them all... :P


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 2:36 am 
Newbie

Joined: Tue Jan 08, 2008 2:20 am
Posts: 4
Hi,

Thanks for your Info.

I am using CRUD Command to perform the update operation.

CRUDCommand updateCommand = new CRUDCommand();
//intiailzie update operation.

//set the User Object.
updateCommand.setValue( User);

//set the Command
Command commandOut = commandDispatcher.dispatchCommand( updateCommand);

If i execute the command the following query executed using the hbm.xml

Update User set user_value = 'xx' where user_id = 1;
since user_id is the primary key. I want to perform update using user_name..?

How to perform the operation


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 10, 2008 6:21 am 
Newbie

Joined: Tue Jan 08, 2008 2:20 am
Posts: 4
Hi,
How to perform the insert using the create Query.
Please ur suggesstion, I googled but not yet found the solution.

Thx.


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.