• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to hbm.xml

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i have very basic problem regarding hibernate.the following is DDL of the table which i want to map to class.

CREATE TABLE `corporate_levels_history` (
`corporate_level_id` int(10) unsigned NOT NULL,
`corporate_level_code` int(10) unsigned NOT NULL,
`corporate_level_name` varchar(45) NOT NULL,
`corporate_level_description` varchar(500) NOT NULL,
`modified_by` varchar(45) NOT NULL,
`modified_on` datetime NOT NULL,
`approval_status` varchar(2) NOT NULL,
`remark` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

you can see above table does not have primary key.

can any one tell me what will be the hbm.xml contents?

please help me. thanks in advance.

thanks,
-Pankaj
 
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


you can see above table does not have primary key.


First and foremost, I'd fix that. Entities without primary keys cannot be considered relational data (since without a unique identifier they can't participate in relationships) so using a Object-Relational Mapping tool with such data is difficult.

If you can't change the DDL then your only option is to map all the fields in the table as one big composite key.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If you are using oracle as your database you can use the oracle generated rowid as your primary key. Hibernate provides support for the rowid. In this scenario you might not require a primary key.
This solution will work only if you are going to use this table for fetching the data. For inserting data you might have to use a composite key as Paul suggested.

Ketan.
 
it's a teeny, tiny, wafer thin ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic