Skip to content
Advertisement

DuplicateMappingException contains physical column name referred to by multiple logical column names on adding passportId to the Student entity

This code is causing the following exception on the startup

JavaScript

I’m using H2 in-memory database.

Student entity:

JavaScript

Passport entity:

JavaScript

Question 1: What is the reason for org.hibernate.DuplicateMappingException?

Question 2: Why does adding the following annotation to passportId in the Student entity resolve the issue?

JavaScript

PS: I know similar questions has been asked earlier but I couldn’t understand the answer for these two questions from those other threads.

Advertisement

Answer

Answer 1

The reason is that you have two writable mappings for the same database column and this is not allowed

Answer 2

Making one of the mappings read-only solves the problem because then only one mapping will be writable

Advertisement