0

The hibernate document says that the class that we use for composite-id should implement serializable, here is the document link that I am going through: http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/mapping.html#mapping-declaration-compositeid

The persistent class must override equals() and hashCode() to implement composite identifier equality. It must also implement Serializable.

But why it is required to implement serializable?

I have gone through this SO link: Why composite-id class must implement Serializable?

but I am not understanding the answer given there, please help me in understanding the concept here.

Community
  • 1
  • 1
Chaitanya
  • 15,403
  • 35
  • 96
  • 137

1 Answers1

2

Because hibernate uses a cache which can store individual values, ids especially. for non-primitive classes, there needs to be a way to convert those individual values into bytes for transport and storage in the cache. the mechanism that hibernate uses for non-primitive classes is java serialization.

jtahlborn
  • 52,909
  • 5
  • 76
  • 118