-1

I am working with legacy database, In which I have a database table, but table doesn't have "ID" column. I wanted to map that table with Hibernate Mapping file. Is it possible? if yes then how?
Thanks in Advance!!

The table structure is as follows

EmployeeEx // table Name

 empName address p_address emp_type
Siddharth
  • 197
  • 1
  • 14
  • 1
    Is there something unique you could use as an id, `empName` for example? Otherwise you might have to use a composite key. Not having a proper id will have a performance impact. – Boris the Spider Mar 20 '14 at 10:39
  • I don't think it is possible. You can try with segregate key in some way. – Balaji Reddy Mar 20 '14 at 10:49

1 Answers1

1

Primary key does not have to be exactly "ID" column.

If there is a unique column in your table, such as "empName", you should anotate it with @Id in the class or write mapping file according to manual at http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch05.html#mapping-declaration-id

If there is a unique combination of columns in your table, you should use a composite key. You can read about it in section 5.1.2.1. Composite identifier on link above. Some hints about it are also on other question (Hibernate/persistence without @Id)

If there is no unique combination, then I am afraid that there is no way how to use hiberante in your case: (Mapped classes must declare the primary key column of the database table.) from the link above.

Community
  • 1
  • 1
Jan Dušek
  • 68
  • 6