How to map a column to a JPA property if it was already mapped in an @ManyToOne association when using Hibernate


I’d like to modify a database field (Char[50]) , as a java String field, via @Column, and a setter method.

But the Column is already used , to create an object field, via @ManyToOne and @JoinColumn. So, when I try to create the String field with @Column I get a org.hibernate.MappingException: Repeated column in mapping for entity: ... (should be mapped with insert="false" update="false") error.

Is there a solution? I’d expect it’d be possible to use the same column for different things?


Yes, it is possible. You just have to do what the error message tells you.

So, this is how you map the repeated column:

@Column(name = "my_char_column", insertable="false" updateable="false")
private String myProperty.