# Hibernate 5 and using @GeneratedValue inside @Embeddable annotated objects used as composite primary keys

**URL:** <https://discourse.hibernate.org/t/hibernate-5-and-using-generatedvalue-inside-embeddable-annotated-objects-used-as-composite-primary-keys/3091>\
**Category:** Hibernate ORM\
**Created:** [August 14, 2019, 2:04pm UTC](https://discourse.hibernate.org/t/hibernate-5-and-using-generatedvalue-inside-embeddable-annotated-objects-used-as-composite-primary-keys/3091 "2019-08-14T14:04:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bastien.gabriel](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@bastien.gabriel](https://discourse.hibernate.org/u/bastien.gabriel)\
**Post date:** [August 14, 2019, 2:04pm UTC](https://discourse.hibernate.org/t/hibernate-5-and-using-generatedvalue-inside-embeddable-annotated-objects-used-as-composite-primary-keys/3091/1 "2019-08-14T14:04:25Z")

</div>

I’m migrating JPA entities from OpenJPA 2.2.x (JPA 2.0) to Hibernate 5.2 (JPA 2.1) and I’ve noticed a peculiar problem. Many of my generated ids are not being populated.  
Many of my entities contain composite keys contained in classes annotated as **Embeddable**. These classes contain attributes annotated with **Column** , **GeneratedValue** , and **SequenceGenerator**.

PLEASE NOTE: I’m really trying to avoid using **IdClass** because it would require massive code changes in the project to add all the primary key fields into the entities themselves.

```java
@Embeddable
public class LinkPK {

	@GeneratedValue(generator = "seq_gen", strategy = GenerationType.SEQUENCE)
	@SequenceGenerator(name = "seq_gen", sequenceName = "LK_SQNBR", allocationSize = 1)
	@Column(name = "LK_SQNBR")
	private Integer linkSequenceNbr;

	@Column(name = "LK_FLT_SQNBR", nullable = false, updatable = false)
	private Integer linkFlightSequenceNumber;

```

Which is used as a primary key for:

```java
@Entity
@Table(name="LINK")
public class Link {
	@EmbeddedId
	private LinkPK id = new LinkPK();

```

When I persist new “Link” objects I would expect the linkSequenceNbr field to be populated by a value retrieved from the LK\_SQNBR sequence. However Hibernate is simply attempting to insert the record with a null value for linkSequenceNbr. I don’t see any select statements to the LK\_SQNBR sequence in the logs.
