Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why hibernate forcing serialization in session.get method

 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic