Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

composite primary keys

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • 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: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic