• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to hbm.xml

 
Pankaj Bagul
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Ketan Jambhekar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic