Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes why hibernate forcing serialization in session.get method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "why hibernate forcing serialization in session.get method" Watch "why hibernate forcing serialization in session.get method" New topic
Author

why hibernate forcing serialization in session.get method

S Reddy
Ranch Hand

Joined: May 17, 2007
Posts: 45
I see that hibernate's session.get() and load() methods is accepting only Serializable IDs as argument to get Entities.

As per my understanding of hibernate, it will generate an SQL statement and send it to DBMS when it needs to get a row from DB.
It will never need to send a java object over network.

In that case why hibernate is forcing serialization on us? It can easily use Class to accept IDs.
Even if Serialization has many benefits, I would like to take that decision of making ID objects Serializable on my own.
Is there any specific reason there which I am missing?

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


It will never need to send a java object over network.

It will if Hibernate is used in a distributed environment, or if the second level cache implementation serializes anything it will need POJOs to be serializable. What downside are you worried about that would stop you having your POJOs implement Serializable?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
S Reddy
Ranch Hand

Joined: May 17, 2007
Posts: 45

I don't see any downside in having to make POJOs implement Serializable. But just thinking that why somebody else has to force me to do something when it is not absolutely necessary?
If I am going to use hibernate in distributed environment I would make POJOs serializable anyway, hibernate shouldn't forcing me.

And If it ts that Secondary cache implementations needed, why only IDs need Serializable and not actual entities?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why hibernate forcing serialization in session.get method
 
Similar Threads
Hibernate: session.get()
Hibernate is returning proxy objects even if no matching row is found on the database
Automatic Optimistic Concurrency
I am getting null value for particular column, while loading the object.
Hibernate