aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate" Watch "hibernate" New topic
Author

hibernate

hari vallabh shukla
Greenhorn

Joined: Jan 31, 2013
Posts: 21
why serializable interface has taken in hibernate get function i.e POJO pojo=session.get(POJO.class ,serializable szlr);
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

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:



[How To Ask Questions][Read before you PM me]
hari vallabh shukla
Greenhorn

Joined: Jan 31, 2013
Posts: 21
we do not implement serializable interface on POJOID class so JVM take responsibility to implement for us
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

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

Joined: Jan 31, 2013
Posts: 21
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

Joined: Mar 07, 2010
Posts: 1666
    
    7

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

Joined: Jan 31, 2013
Posts: 21
Thanks for giving your knowlege, now my doubt has cleared
hari vallabh shukla
Greenhorn

Joined: Jan 31, 2013
Posts: 21
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

Joined: Jan 31, 2013
Posts: 21
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate