User-defined @SoftDelete(columnName = "is_deleted"). The entity has the deleted attribute and a Duplicate column error is reported when the column is saved

@Entity
@Table(name = "\"user\"")
@SoftDelete(columnName = "is_deleted")
public class UserEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;


    private String name;

    @Column(name = "is_deleted")
    private Boolean deleted;
}
UserEntity user=new UserEntity();
		user.setName("smallbun");
		s.persist(user);

Error:

org.hibernate.exception.SQLGrammarException: could not prepare statement [Duplicate column name "IS_DELETED"; SQL statement:
insert into "user" (is_deleted,name,is_deleted,id) values (?,?,false,?) [42121-224]] [insert into "user" (is_deleted,name,is_deleted,id) values (?,?,false,?)]

It’s a bug that you are not seeing a bootstrap error. Please try to create a reproducer with our test case template (hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) and if you are able to reproduce the issue, create a bug ticket in our issue tracker(https://hibernate.atlassian.net) and attach that reproducer.

The solution is to make the @Column(insertable = false, updatable = false)

https://hibernate.atlassian.net/jira/software/c/projects/HHH/issues/HHH-17461

1 Like