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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • 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
Hi,

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"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="walgreens.pos.dl.analysis.db.UnrecognizedDataBean"
table="UNRECOGNIZED_DATA">
<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"
class="walgreens.pos.dl.parse.Score">
<property name="percentMatch" type="int" not-null="false"
column="PERCENTAGE_MATCH" />
<property name="matchingParser" type="string"
not-null="false" column="CLOSEST_MATCHED" />
<property name="matchingCriterionIDs" not-null="false"
column="MATCHING_CRITERIA" />
<!--array name="matchingCriterionIDs" cascade="all" fetch="join">
<key column="MATCHING_CRITERIA" />
<list-index column="MATCHING_CRITERIA" />
<one-to-many class="String" />
</array-->
</component>
<!-- score bean still needs to be mapped -->
</class>
</hibernate-mapping>



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!!!
 
Bartender
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?
reply
    Bookmark Topic Watch Topic
  • New Topic