views:

120

answers:

2

When using Hibernate:

Must I identify an id or composite id for each entity, What about if I want to use table without any primary key and without composite key ...

Thanx in advance

+2  A: 

A table without a key isn't a good relational model. I would not recommend it.

Hibernate's best practices say you should have an id. Composite ids are workable for legacy apps, but not always the best idea.

If you really must have a table without a key, I'd suggest that you shouldn't use Hibernate. It's an ORM tool, and it sounds like you're thinking about neither objects nor relational tables properly. Start with JDBC.

duffymo
+1  A: 

I you are working with a legacy schema then you need to have a look at composite-id.

cherouvim
Link should be http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-compositeid
Roalt