Hibernate/JPA: ManyToOne to behave as LEFT OUTER JOIN instead of foreign Key

401 Views Asked by At

I have two entity: Person and Email. The relationship between them is ManyToOne. The idea is Every household will have one email - and all the person in a house will share same email.

I also have a case where few households doesn't have email address.

Now when I create a Person it fails with ConstraintViolationException because at times the email for household is not there.

I have tried optional=true and nullable = true but it didn't help.

My understanding is @JoinColumn is creating a Foreign Key relationship. But I actually require a LEFT OUTER JOIN so that if the email is null, it is ignored.

How can I achieve it in JPA / Hibernate?

EDIT: The DDL is generated by Hibernate. I am using following properties: spring.jpa.generate-ddl=true spring.jpa.hibernate.use-new-id-generator-mappings=true spring.jpa.properties.hibernate.jdbc.time_zone=UTC spring.jpa.open-in-view=false spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

0

There are 0 best solutions below