Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read the data from database using hibernate when the id is String

 
Tejaraja Kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as i know the data can be load by using the code

StudentDTO readDetails=(StudentDTO)session.load(StudentDTO.class, new Integer(1));

but the id am using in database is in String Format, So how can i read and display it in console


..
Thnks in advance
 
Dave Tolls
Ranch Hand
Posts: 2110
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a String instead of an Integer.
The load() method takes a Serializable for the id.

Edit: I will say that id columns that are Strings would raise a question mark from me if I were reviewing the model.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tejaraja Kumar,

First of all, a warm welcome to CodeRanch!

Tejaraja Kumar wrote:but the id am using in database is in String Format, So how can i read and display it in console

I agree with Dave! String IS-A Serializable so you could simply use "1" or String.valueOf() as the second parameter in the load() method.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic