How to use Hibernate with table not having primary key

Discussions

General J2EE: How to use Hibernate with table not having primary key

  1. Hi All, Can anybody tell me is there a way to use Hibernate with the tables that doesn't have primary key. I know that not having primary/unique key for a table is a design fault, but what if i have to work with a legacy database tables that may not have primary/unique key constraints by using Hibernate technology. Thanks, K. Siva Prasad Reddy.
  2. When you don't have a primary key in your table, then also you can use hibernat the same way as we do with primary key. There won't be any difference. The database won't check for the constraints and will store data with same keys also.
  3. Hi, Thanks for your reply. But according to hbm DTD, i have to specify either or property which means i can't have two rows with same values for the id column(s)/propertie(s). Thanks, K. Siva Prasad Reddy.
  4. Hi, Yess yoy have to specify you id with which you will identify unique records in or but if you don't have that constraint on the table then also you can give the column name and you can store multiple same values of that colomn..
  5. you can use hibernate mapping a table without id,but if you try to update or get,load etc,there will be throw a exception