Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java hibernate spring集成中的一对多映射出错_Java_Spring_Hibernate_Hibernate Mapping - Fatal编程技术网

Java hibernate spring集成中的一对多映射出错

Java hibernate spring集成中的一对多映射出错,java,spring,hibernate,hibernate-mapping,Java,Spring,Hibernate,Hibernate Mapping,我需要使用一对多映射两个pojo类,但得到以下错误 com.mysql.jdbc.MysqlDataTruncation:数据截断:第1行“testCaseStepsform”列的数据太长 当我看到hibernate创建的表时,我发现创建了一个数据类型为blob的列 我在下面添加代码 @Entity @Table(name="TEST_CASE_DESC") public class TestCaseForm implements Serializable{ /** *

我需要使用一对多映射两个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。不要同时使用它。

分开,@xl0e回答

您需要更正映射

@OneToMany(mappedBy = "testCaseForm", cascade = CascadeType.ALL)
public ArrayList<TestCaseStepsForm> getTestCaseStepsform() {
    return testCaseStepsform;
}