Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join column must be defined with the same insertable and updatable attributes

i upgraded to spring boot 3.2.1 (that use hibernate 6.4.1)

I get this error since this upgrade when i try to boot application

Join column 'query_type_id' on collection property 'com.acme.demo.common.QueryType.queryStatus' must be defined with the same insertable and updatable attributes

@Data
@Entity
@Table
public class QueryType {

    @Id
    @SequenceGenerator
    @GeneratedValue
    private Long QueryTypeId;

    private String code;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "queryType")
    private Set<Query> queries = new HashSet<>(0);

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "QUERY_STATUS_TYPE", schema = "", joinColumns = { @JoinColumn(name = "QUERY_TYPE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "QUERY_STATUS_ID", nullable = false, updatable = false) })
    private Set<QueryStatus> queryStatus = new HashSet<>(0);

}

@Data
@Entity
@Table
@DiscriminatorColumn(name = "QUERYTYPE_CODE", discriminatorType = DiscriminatorType.STRING)
public abstract class QueryStatus {

    @Id
    @SequenceGenerator
    @GeneratedValue
    @NotNull
    private Long queryStatusId;

    private String code;

    private String description;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "queryStatus")
    private Set<Query> queries = new HashSet<>(0);

}

i have some class who extends QueryStatus

I just don't understand why i get this error suddendly

that worked fine with spring boot 3.2.0 (that use hibernate 6.3.1)

like image 263
robert trudel Avatar asked Sep 03 '25 17:09

robert trudel


1 Answers

You can probably remove the updatable since in previous versions it wouldn't prevent the adding or removing of members of the relationship.

joinColumns = { @JoinColumn(name = "QUERY_TYPE_ID", nullable = false ) }, inverseJoinColumns = { @JoinColumn(name = "QUERY_STATUS_ID", nullable = false)

If your intention is to make the relationship readonly, than you need to add both insertable=false and updatable=false

joinColumns = { @JoinColumn(name = "QUERY_TYPE_ID", nullable = false, insertable=false, updatable=false) }, inverseJoinColumns = { @JoinColumn(name = "QUERY_STATUS_ID", nullable = false, insertable=false, updatable=false)

This is based on the responses from the related Hibernate ticket https://hibernate.atlassian.net/browse/HHH-17586

like image 139
Ralph Ritoch Avatar answered Sep 05 '25 15:09

Ralph Ritoch