尝试@ManyToOne在单独的表中创建关系TestEntity并TestAttr获取错误响应:
org.hibernate.PropertyValueException: not-null property references a null or transient value : com.test.TestEntity.testAttr; nested exception is javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value : com.test.TestEntity.testAttr
这是有问题的实体:
@Table(name = "test_table")
public class TestEntity{
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "test_attr_test_entity", joinColumns = {@JoinColumn(name = "test_entity_id", nullable = false, updatable = false)},
inverseJoinColumns = {@JoinColumn(name = "test_attr_id", nullable = false, updatable = false)})
private TestAttr testAttr;
.
.
.
}
并且当更改为@ManyToMany它时,它可以正常工作。
持久化代码:
testEntityRepository.save(testEntity)
