字段列表中未知的列x [英] Unkown column x in field list

查看:54
本文介绍了字段列表中未知的列x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在两个表之间创建一对多关系. TestCase有一个FK,称为Type

I'm trying to create a one to many relation between two tables. TestCase has a FK called Type

基本上,许多测试案例可以具有一种类型,但是一个testCase只能具有一种类型.

Basically many testCases can have one type but a testCase can only have one type.

我在这里想念什么?

TestCase表

TestType表

但是我得到

字段列表中未知的列idtestType

Unkown column idtestType in field list

型号

public class TestCase {

private int id;
private String name;
private TestType type;
private byte[] data;
private String creationDate;
private String createdBy;

public TestCase() {
}

public TestCase(String name, TestType type, byte[] data, String creationDate, String createdBy) {
    this.name = name;
    this.type = type;
    this.data = data;
    this.creationDate = creationDate;
    this.createdBy = createdBy;
}

TestCase.xml

TestCase.xml

    <hibernate-mapping>
<class name="com.atp.Model.TestCases.TestCase" table="testCases">
    <meta attribute="class-description">
        This class contains the testCases details.
    </meta>
    <id name="id" type="int" column="idtestCase">
        <generator class="native"/>
    </id>
    <property name="name" column="name" type="string"/>
    <many-to-one name="type" class="com.atp.Model.TestCases.TestType" fetch="select">
        <column name="idtestType"/>
    </many-to-one>
    <property name="data" column="data" type="binary"/>
    <property name="creationDate" column="creationDate" type="string"/>
    <property name="createdBy" column="createdBy" type="string"/>
</class>
</hibernate-mapping>

型号

public class TestType {

private int id;
private String desc;
private Set<TestCase> testCases = new HashSet<>(0);

public TestType() {
}

public TestType(String desc, Set<TestCase> testCases) {
    this.desc = desc;
    this.testCases = testCases;
}

TestType.xml

TestType.xml

   <hibernate-mapping>
<class name="com.atp.Model.TestCases.TestType" table="testType">
    <meta attribute="class-description">
        This class contains the testCases details.
    </meta>
    <id name="id" type="int" column="idtestType">
        <generator class="native"/>
    </id>
    <property name="desc" column="desc" type="string"/>
    <set name="testCases">
        <key>
            <column name="idtestType" />
        </key>
        <one-to-many class="com.atp.Model.TestCases.TestCase" />
    </set>
</class>
</hibernate-mapping>

尝试将其添加到数据库中

Trying to add it to the database

 public static void addTestCase(String testName, String type, MultipartFile file, String createdBy) {
    byte[] data;
    Date date = new Date();
    final DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    String creationDate = sdf.format(date);
    TestType testType = new TestType();
    testType.setDesc(type);

    try {
       data = file.getBytes();
        TestCase testCase = new TestCase(testName,testType,data,creationDate,createdBy);
        testType.getTestCases().add(testCase);
        Database.addToDatabase(testCase);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

推荐答案

您缺少

idtestType 

TestCase表中的列.

column in the TestCase table.

或者,如果您想使用现有表中的type列,则您的TestCase.xml-Mapping错误,应该是

Or, if you want to use the type column in the existing table your TestCase.xml-Mapping is wrong and should be

    <many-to-one name="type" class="com.atp.Model.TestCases.TestType" fetch="select">
    <column name="type"/>
</many-to-one>

(列是类型",而不是"idtestType")

(column is "type" instead of "idtestType")

这篇关于字段列表中未知的列x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆