• Post Reply Bookmark Topic Watch Topic
  • New Topic

Create table without any key in Hibernate  RSS feed

Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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!!!
Paul Sturrock
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!