Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Hibernate: one-to-one composite foreign key : Strange Scenario

Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 classes viz. Product and ProductBasic which has one-to-one relationship.
Product is mapped to a table PRODUCT which has PRODUCTID as PK.
ProductBasic is mapped to a table PRODUCTBASIC which has PRODUCTID,USETYPE and STARTTTIMESTAMP as composite key. Also PRODUCTID
is the foreign key referencing PRODUCT table...

When i am saving Product (with cascade for ProductBasic):
For Product, it's taking persister.identifierType as org.hibernate.type.CustomType
For ProductBasic, it's taking persister.identifierType as org.hibernate.type.ComponentType

Assume productId='1'
When i call,
a) For Product: it tries to find hashmap of id=1 using org.hibernate.type.StringType.getHashCode() which comes out to be 49 (ASCII)..
b) For ProductBasic: it tries to find hashmap of id=1 using org.hibernate.type.ComponentType.getHashCode() and throws exception:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of

Does it treating ProductBasic as component because it's productId value depends upon Product.productId? Even if it treats
ProductBasic as component, why it is not fetching the proper hashCode() and throwing exception?

There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic