• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

composite primary keys

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per the JPA specifications composite primary keys classes have to be serializable . Can anyone brief why is this condition put?
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the Hibernate framework ever needs to "passivate" as composite key by saving its state temporarily to the hard drive, or even send the data across a network or io connection, the fact that the bean is serializable means that the framework can perform these tasks by using standard Java mechanisms. If the bean is not serializable, Hibernate cannot depend on the built-in serialization features of the JVM.

-Cameron McKenzie
 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but why only with composite primary key.?
if i have primary key member specifed in a class , which is not serializable...then also hibernate framework works
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What type of non-serializable instance have you specified as a primary key? And how is Hibernate mapping it to a database column?
 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
say a simple primitive type (int ) is specified in the class and its mapped to some field id in the db.

 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An int is a primitive type. The Serializable commitment is essentially that an object is only made up of the basic primitive types, and if there are non-primitive types, those types be either Serializable or be marked as transient.

All the primitive types are essentially 'serializable', as the JVM can write and read them to various output streams. Of course, technically we can't call primitives "Serializable" because they are not object, but they sorta are.

-Cameron McKenzie
 
Hey cool! They got a blimp! But I have a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic