Archive for the ‘JPA’ Category

Understanding Composite-id with JPA Identifiers @Id Vs @EmbeddedId Vs @IdClass

Sunday, May 11th, 2008

Note - If you're looking for Hibernate Composite-Id example using xml configuration, read our earlier post here. Entities must define an id field. Typically a generated id is fine for most cases, but sometimes we need to add multiple fields corresponding to the database primary key. (legacy database?). The id can ...

Generating a primary key in @ManyToMany with hbm-ddl

Tuesday, April 22nd, 2008

Say, you have two entities which have a many to many relationship (Foo and Bar). Using JPA/Hibernate, they are mapped like this, with the owning entity being Foo. [java] public class Foo { ........ @ManyToMany @JoinTable(name="foos_bars", joinColumns = { @JoinColumn(name = "foo_id") }, inverseJoinColumns = { @JoinColumn(name = "bar_id") }) ...