*
The moose likes Object Relational Mapping and the fly likes storing an objcet with only selected columns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "storing an objcet with only selected columns" Watch "storing an objcet with only selected columns" New topic
Author

storing an objcet with only selected columns

indu iyengar
Ranch Hand

Joined: Jul 30, 2010
Posts: 115
Hi all,

My requirement is store only selected columns in the database for an object using Hibernate...

When i set the values and try to store with desired columns , it s not showing any error, but in the db the object is not updating.

please tell me how to .. ?

thanks ,
Indu
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you give us more detail? Perhaps post your code?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
indu iyengar
Ranch Hand

Joined: Jul 30, 2010
Posts: 115
thanks for the reply..

Register Student is a pojo with 4 fields

In Register Form.jsp i have only 2 fields
Student Name and DOB

the table in DB is with 4 corresponding columns as in Pojo.

Here I need to store only studentName and DOB in DB(student ID is increment generator) , and in return i need to give studentID for the student .

Mycode to update
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You will need to load the object you want to update, otherwise Hibernate has no way of knowing what it is you are trying to update.
indu iyengar
Ranch Hand

Joined: Jul 30, 2010
Posts: 115
Thaks Paul for replying... how to load an object without knowing its identifier ? because identifier will be created once the object is stored.. Please tell me is there any other way of doing for this ?

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


how to load an object without knowing its identifier

This cannot be done. You can't find anything in a relational database unless you can identify it.


because identifier will be created once the object is stored

This sounds to me like you are trying to create rather than update an object, is that so? In which case you need to use the save method, not the update method of Session.
indu iyengar
Ranch Hand

Joined: Jul 30, 2010
Posts: 115
yes.. am using save method only..
but object is not creating in database
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


yes.. am using save method only..

Not in the code posted above, have you changed it?

Where do you commit your transaction?
indu iyengar
Ranch Hand

Joined: Jul 30, 2010
Posts: 115
yes.. I changed it to no exception is coming.. but not creating any object in DB
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Where do you commit your transaction?
indu iyengar
Ranch Hand

Joined: Jul 30, 2010
Posts: 115
oh sorry Paul, I forgot to commit the transaction .. It is storing the object properly...

Thanks a lot..
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing an objcet with only selected columns
 
Similar Threads
JSP Invoking another JSP in Iframe
Constructing value objects using HQL or Creteria
SelectionChangedListener?
no data found error
Export to excel without hiding columns