gpt4 book ai didi

java - hibernate-spring 集成中一对多映射错误

转载 作者:行者123 更新时间:2023-12-02 13:40:48 25 4
gpt4 key购买 nike

我需要使用一对多映射两个 pojo 类,但出现以下错误 com.mysql.jdbc.MysqlDataTruncation:数据截断:第 1 行“testCaseStepsform”列的数据太长

当我看到hibernate创建的表时,发现创建了一个数据类型为blob的列

我正在添加下面的代码。

@Entity
@Table(name="TEST_CASE_DESC")
public class TestCaseForm implements Serializable{

/**
*
*/
private static final long serialVersionUID = 10001234L;
@Id
@Column(name="TEST_CASE_ID")
private String testCaseId;
@Column(name="PROJECT_NAME")
private String projectName;
@Column(name="PROJECT_ID")
private String projectId;
@Column(name="RELEASE_NAME")
private String releaseName;
@Column(name="RELEASE_ID")
private String releaseId;
@Column(name="ITERATION")
private String iteration;
@Column(name="TITLE")
private String title;
@Column(name="CREATED_BY")
private String createdBy;
@Column(name="CREATION_DATE")
private Date creationDate;
@Column(name="DESCRIPTION")
private String description;
@Column(name="PRE_CONDITION")
private String preCondition;
@Column(name="POST_CONDITION")
private String postCondition;
@Column(name="TYPE")
private String type;
@Column(name="IMPORTANCE")
private String importance;


private ArrayList<TestCaseStepsForm> testCaseStepsform = new ArrayList<TestCaseStepsForm>();

public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPreCondition() {
return preCondition;
}
public void setPreCondition(String preCondition) {
this.preCondition = preCondition;
}
public String getPostCondition() {
return postCondition;
}
public void setPostCondition(String postCondition) {
this.postCondition = postCondition;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getRelease() {
return releaseName;
}
public void setReleaseName(String releaseName) {
this.releaseName = releaseName;
}
public String getReleaseId() {
return releaseId;
}
public void setReleaseId(String releaseId) {
this.releaseId = releaseId;
}
public String getIteration() {
return iteration;
}
public void setIteration(String iteration) {
this.iteration = iteration;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getReleaseName() {
return releaseName;
}
public String getImportance() {
return importance;
}
public void setImportance(String importance) {
this.importance = importance;
}
@OneToMany(mappedBy = "TEST_CASE_DESC", cascade = CascadeType.ALL)
public ArrayList<TestCaseStepsForm> getTestCaseStepsform() {
return testCaseStepsform;
}

public void setTestCaseStepsform(ArrayList<TestCaseStepsForm> testCaseStepsform) {
this.testCaseStepsform = testCaseStepsform;
}
public String getTestCaseId() {
return testCaseId;
}
public void setTestCaseId(String testCaseId) {
this.testCaseId = testCaseId;
}
}


@Entity
@Table(name="TEST_CASE_STEP")
public class TestCaseStepsForm implements Serializable{

/**
*
*/
private static final long serialVersionUID = 123456788091L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="SERIAL_NUMBER")
private String serialNumber;
@Column(name="TEST_CASE_ID")
private String testCaseId;
@Column(name="INPUT")
private String input;
@Column(name="EXPCETED_OUTPUT")
private String expectedOutput;
@Column(name="STATUS")
private String status;

private TestCaseForm testCaseForm;

public String getTestCaseId() {
return testCaseId;
}
public void setTestCaseId(String testCaseId) {
this.testCaseId = testCaseId;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getExpectedOutput() {
return expectedOutput;
}
public void setExpectedOutput(String expectedOutput) {
this.expectedOutput = expectedOutput;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}

@ManyToOne( fetch = FetchType.LAZY)
@JoinColumn(name = "TEST_CASE_ID", nullable = false)
public TestCaseForm getTestCaseForm() {
return testCaseForm;
}
public void setTestCaseForm(TestCaseForm testCaseForm) {
this.testCaseForm = testCaseForm;
}
public String getSerialNumber() {
return serialNumber;
}
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
}
}

@Configuration
public class TestCaseConfig {

@Bean(name="testCaseForm1")
public TestCaseForm testCaseForm1(){

TestCaseForm tst = new TestCaseForm();
tst.setTestCaseId("1122233");
tst.setProjectId("1234");
tst.setReleaseName("June");
tst.setReleaseId("1707");
tst.setIteration("2");
tst.setProjectName("ExpressPay");
tst.setTitle("ExpressPay");
tst.setCreatedBy("Anirban Deb");
tst.setCreationDate(new Date());
tst.setDescription("ExpressPay Login");
tst.setPreCondition("Active account");
tst.setPostCondition("success");

TestCaseStepsForm str1 = new TestCaseStepsForm();
str1.setTestCaseId("1122233");
str1.setInput("Hello World");
str1.setExpectedOutput("Bye Bye world");
str1.setStatus("Run");
str1.setTestCaseForm(tst);

TestCaseStepsForm str2 = new TestCaseStepsForm();
str2.setTestCaseId("1122233");
str2.setInput("Hello World");
str2.setExpectedOutput("Bye Bye world");
str2.setStatus("Run");
str1.setTestCaseForm(tst);

tst.getTestCaseStepsform().add(str1);
tst.getTestCaseStepsform().add(str2);
return tst;
}
}

public class Main {

public static void main(String[] args) throws MessagingException {

StopWatch stopWatch = new StopWatch();
stopWatch.start();

ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("core-bean.xml");
TestCaseForm test1 = context.getBean("testCaseForm1",TestCaseForm.class);
ITestCaseService testCase = context.getBean("testCaseServiceImp", ITestCaseService.class);
testCase.inserTestCase(test1);
[enter image description here][1]
stopWatch.stop();

System.out.println("Time taken in execution : "+stopWatch.getTotalTimeSeconds());
}
}

最佳答案

您应该选择注释对象属性或 getter。不要同时使用它。

关于java - hibernate-spring 集成中一对多映射错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42747549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com