Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.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-回滚:org.Hibernate.MappingException:未知实体_Java_Sql_Hibernate_Struts2_Pojo - Fatal编程技术网

Java Hibernate-回滚:org.Hibernate.MappingException:未知实体

Java Hibernate-回滚:org.Hibernate.MappingException:未知实体,java,sql,hibernate,struts2,pojo,Java,Sql,Hibernate,Struts2,Pojo,我已经编写了一些代码来将数据插入我的SQL数据库。实际上,我正在尝试使用Hibernate学习Struts 2。但是,不幸的是,我在提交表格后遇到了一个问题 我找不到此错误消息的原因。我的try&catch块抛出如下错误: Exception in saveOrUpdate() Rollback :org.hibernate.MappingException: Unknown entity: v.esoft.pojos.Employee Pojo(Employee.java): @Entit

我已经编写了一些代码来将数据插入我的SQL数据库。实际上,我正在尝试使用Hibernate学习Struts 2。但是,不幸的是,我在提交表格后遇到了一个问题

我找不到此错误消息的原因。我的try&catch块抛出如下错误:

Exception in saveOrUpdate() Rollback  :org.hibernate.MappingException: Unknown entity: v.esoft.pojos.Employee
Pojo(
Employee.java
):

@Entity
@Table(name = "employee", catalog = "eventusdb")
public class Employee implements java.io.Serializable {

    private Integer empId;
    private String name;
    private String website;

    public Employee() {
    }

    public Employee(String name, String website) {
        this.name = name;
        this.website = website;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "emp_id", unique = true, nullable = false)
    public Integer getEmpId() {
        return this.empId;
    }

    public void setEmpId(Integer empId) {
        this.empId = empId;
    }

    @Column(name = "name", nullable = false)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "website", nullable = false, length = 65535)
    public String getWebsite() {
        return this.website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

}
    <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 10, 2013 4:29:04 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="v.esoft.pojos.Employee" table="employee" catalog="eventusdb">
        <id name="empId" type="java.lang.Integer">
            <column name="emp_id" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="name" not-null="true" />
        </property>
        <property name="website" type="string">
            <column name="website" length="65535" not-null="true" />
        </property>
    </class>
</hibernate-mapping>
还有
Employee.hbm.xml

@Entity
@Table(name = "employee", catalog = "eventusdb")
public class Employee implements java.io.Serializable {

    private Integer empId;
    private String name;
    private String website;

    public Employee() {
    }

    public Employee(String name, String website) {
        this.name = name;
        this.website = website;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "emp_id", unique = true, nullable = false)
    public Integer getEmpId() {
        return this.empId;
    }

    public void setEmpId(Integer empId) {
        this.empId = empId;
    }

    @Column(name = "name", nullable = false)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "website", nullable = false, length = 65535)
    public String getWebsite() {
        return this.website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

}
    <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Sep 10, 2013 4:29:04 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="v.esoft.pojos.Employee" table="employee" catalog="eventusdb">
        <id name="empId" type="java.lang.Integer">
            <column name="emp_id" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="name" not-null="true" />
        </property>
        <property name="website" type="string">
            <column name="website" length="65535" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

如果实体未映射,则应检查hibernate配置。Hibernate是用于将POJO(实体)映射到数据库模式对象的ORM框架。您没有配置或hibernate找不到对象
员工的映射。配置文件为
hibernate.cfg.xml
应该包含到资源
Employee.hbm.xml
的映射。假设此文件与
Employee
class位于同一文件夹中。然后映射将是

<mapping resource="v/esoft/pojos/Employee.hbm.xml"/>

注意,根据Hibernate版本的不同,基于注释的配置可能会有所不同,并且可能需要额外的库

哪一行号。你得到这个例外?只有我不知道的消息?如何知道哪一行出现异常?使用
e.printStackTrace()除了您的
系统.out.println()
之外。对于将来,使用Log4J或类似的工具,它将为您解析异常的StackTrace。@AndreaLigios这个问题实际上解决了,我必须映射我的POJO类,但在运行此代码后,它不会将我的表单数据插入表中。我成功插入了
1行。
消息,但没有在我的表中插入数据。感谢我在hibernate.cfg文件中添加了
,现在这个问题已经解决。但现在它并没有插入到我的数据库代码中。它不会显示此错误的任何错误。可能是什么错误?可能是您未提交的事务,或与数据库相关。谢谢,此问题已解决。也许你能帮我做这个