Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate

 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why serializable interface has taken in hibernate get function i.e POJO pojo=session.get(POJO.class ,serializable szlr);
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It expects the @Id field to be Serializable. This will usually be the case anyway if it is a basic type like Integer or Long, however often times people will have Embedded classes or Primary Key classes to support composite keys. In this case these objects must also implement Serializable.

So what you have there is this:

 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we do not implement serializable interface on POJOID class so JVM take responsibility to implement for us
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we do not implement serializable interface on POJOID class


JSR-317 requires it so you need to.


so JVM take responsibility to implement for us


What leads you to believe this is going to happen? The JVM is not going to just make something Serializable for you. In 99% of cases it is as simple as adding 'implements Serializable' to your ID class and having your IDE generate a serial version id. You can make this change in less time than it takes me to type this.
 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i understand that POJOId class implement serializable interface but some time we give Integer,Long ,String etc in ID field which donot implement serializable interface then how compiler handle that situation
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those classes you mentioned do implement Serializable. Look at the implemented interfaces on the API.

http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html
 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for giving your knowlege, now my doubt has cleared
 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why serializable interface has taken in hibernate get function i.e POJO pojo=session.get(POJO.class ,serializable szlr); I ant to ask why not Object class has taken instead of serialization
 
hari vallabh shukla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By studying book i got an idea that one of the use of Serializable interface is that to convert object into bytestream and store in file or database ,so to convert POJOId object into relational structure which database can understand serializable interface has taken
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic