【发布时间】:2021-10-27 12:42:10
【问题描述】:
我有以下实体:
TestCommentEntity
@Entity
@Table(name = "test_comment")
public class TestCommentEntity {
@EmbeddedId
private TestCommentEntityPK testCommentEntityPK;
@Column(name = "comment", nullable = false)
private String comment;
}
TestCommentEntityPK
@Data
@Embeddable
public class TestCommentEntityPK implements Serializable {
//This is suppose to be the join between the two tables:
@Column(name = "test_id", nullable = false)
private String testId;
@Column(name = "user_id", nullable = false)
private String userId;
}
测试实体
@Entity
@Table(name = "test")
public class TestEntity {
@Id
@Column(name = "test_id", nullable = false)
private String testId;
@Column(name = "user_id", nullable = false)
private String userId;
@Enumerated(EnumType.STRING)
@Column(name = "test_type", nullable = false)
private TestType testType;
@Column(name = "active")
private boolean isActive;
@Column(name = "quality", nullable = false)
private TestQuality quality;
@Column(name = "vote_count")
private int voteCount;
@OneToMany(fetch = FetchType.EAGER, targetEntity = TestCommentEntity.class, cascade = CascadeType.ALL)
@JoinColumn(referencedColumnName = "test_id")
private List<TestCommentEntity> comments;
}
我有以下存储库:
@Repository
public interface TestRepository extends JpaRepository<TestEntity, String> {
}
与
@Repository
public interface TestCommentRepository extends JpaRepository<TestCommentEntity, TestCommentEntityPK> {
}
每当声明:
testRepository.findById(testId)
正在执行,我收到以下错误:
原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'cmets1_.cmets_test_id' in 'field list'
谁能指出我这样做是否正确?
【问题讨论】:
标签: spring-boot hibernate jpa spring-data-jpa