Skip to content
Advertisement

JPA and Hibernate, OneToMany relationship with a composite key using UUID

I’m using SpringBoot with JPA and Hibernate.

I have two entities: Book and Author. A Book can have multiple Authors. So I need a OneToMany relationship.

Into the Author table, my idea is to use a composite key (the book_id and one internal field for example field_a)

I implemented these classes:

JavaScript

When I try to execute my project (I’m using the property spring.jpa.hibernate.ddl-auto=create to generate the DB) I’m obtaining this error:

JavaScript

Any suggestion?

If I try to remove the use of composite-key works fine so, probably the problem it’s related to the implementation or use of the composite key.

Advertisement

Answer

Use either an ID class with Author as:

JavaScript

Or an embeddable that defines the basic fields for your entity as you have already done:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement