Take the 2-minute tour ×

Good evening. When I attempt to create jpa entities using a database connection I am getting some exceptions. Something about id non-existent. I suspect it has something to do with the fact that some of the tables have no primary key. Because when I go through each entity and give it a primary key, the error clears up. How can I create entities on tables that have no primary keys? I am using websphere integration developer (wid) btw.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

All entities have an Id, that is how they work - or more accurately how the specification states it. If there are tables in the database you want to map to entities and the tables don't have a primary key there are several options availble to you.

  • Add a generated Id (managed by JPA or DB) to the table - suggested if you have that freedom.
  • Use a couple of the existing columns in the table as the entity Id (choosing the least numbers necessary to make sure the Id becomes unique).
  • Use all columns, even if there is a theoretical chance of their combination not being unique (would mess up the table/db so care should be taken even in the java layers to not let that happen)
  • ... might be more alternatives I can't think of right now

Should be rather easy to find information about how to do alternative 2 and 3 via a search for JPA and CompositeKey.

Good Luck

share|improve this answer
Didn't think of that. I might end up doing that. Thanks. –  DmainEvent Mar 19 '12 at 10:47
could I perhaps generate embedded types instead? –  DmainEvent Mar 19 '12 at 12:13
Instead of entities or instead as Id for the entity? –  esej Mar 19 '12 at 15:02

Your Answer


