Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Create table without any key in Hibernate

Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Today I was trying to create a table without any ID(primary or composite etc.) When I tried to map that table with corresponding bean, it's giving me compiler error in *.hbm.xml

My mapping is as follows:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<class name="walgreens.pos.dl.analysis.db.UnrecognizedDataBean"
<property name="barcodeData" type="blob" not-null="false"
column="BARCODE_DATA" />
<property name="dateReceived" type="timestamp"
column="DATE_RECEIVED" not-null="false" />
<property name="msrDataTrack1" type="blob" not-null="false"
column="MSR_DATA_TRACK1" />
<property name="msrDataTrack2" type="blob" not-null="false"
column="MSR_DATA_TRACK2" />
<property name="msrDataTrack3" type="blob" not-null="false"
column="MSR_DATA_TRACK3" />
<component name="scoreBean"
<property name="percentMatch" type="int" not-null="false"
<property name="matchingParser" type="string"
not-null="false" column="CLOSEST_MATCHED" />
<property name="matchingCriterionIDs" not-null="false"
<!--array name="matchingCriterionIDs" cascade="all" fetch="join">
<key column="MATCHING_CRITERIA" />
<list-index column="MATCHING_CRITERIA" />
<one-to-many class="String" />
<!-- score bean still needs to be mapped -->

Could anybody explain me why this is happening? Cann't I create a table without ID, there are so many situations where I have to create a table without any ID.

Thanks for early responses in advance!!!
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ignoring Hibernate, defining an entity without a primary key is invalid data modelling in relational databases. An entity you can't uniquely identify in your data cannot participate in relationships so is not relational data.

Hibernate can only map to relational data, hence the error.

Why do you have to create a table without a primary key? Why can't you include a surrogate key?
    Bookmark Topic Watch Topic
  • New Topic