Skip to content

Category Archives: JPA

Migrating from Hibernate 3.3.2, JPA 1 to Hibernate 3.5 CR2 and JPA 2

Starting with version 3.5 (currently CR2), Hibernate Annotations 3.x and Hibernate EntityManager projects have been merged into the Hibernate Core codebase as invidual modules. As a surprising addition, Hibernate Envers subproject is added as well (that’s a great thing as you get Auditing, out of box hereafter). So if you’re stuck with Hibernate 3.3.x and [...]

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

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 either be simple or [...]

Generating a primary key in @ManyToMany with hbm-ddl

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. public class Foo { …….. @ManyToMany @JoinTable(name="foos_bars", joinColumns = { @JoinColumn(name = "foo_id") }, inverseJoinColumns = { @JoinColumn(name = "bar_id") }) public List<bar> getBars() { return bars; [...]