问题描述
我编写了一些代码来将数据插入到我的 sql 数据库中.实际上,我正在尝试使用 hibernate 学习 struts 2.但是,不幸的是,我在提交表单后遇到了问题.
i have written few codes for inserting data into my sql database. actually, i am trying to learn struts 2 with hibernate. but, unfortunately i am facing a problem after submitting my form.
我找不到此错误消息的原因.我的尝试catch 块抛出如下错误:
i could not find the reason for this error message. my try & catch block throws error like:
exception in saveorupdate() rollback :org.hibernate.mappingexception: unknown entity: v.esoft.pojos.employee
pojo(employee.java):
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; } }
还有employee.hbm.xml:
推荐答案
如果实体没有被映射,你应该检查休眠配置.hibernate 是用于将 pojo(实体)映射到数据库模式对象的 orm 框架.您没有配置或休眠找不到对象 employee 的映射.配置文件是 hibernate.cfg.xml 应该包含到资源 employee.hbm.xml 的映射.假设此文件与 employee 类位于同一文件夹中.然后映射将是
if the entity isn't mapped, you should inspect the hibernate configuration. hibernate is orm framework used to map pojos (entities) to the database schema objects. you didn't configure or hibernate couldn't find mapping for the object employee. the configuration file is hibernate.cfg.xml should contain the mapping to the resource employee.hbm.xml. suppose this file is in the same folder as employee class. then the mapping will be
如果您使用基于注解的配置的另一种方法,那么您应该使用 class 属性映射到包含 hibernate/jpa 注解的 pojo.
another approach if you used an annotation based configuration, then you should use class attribute to map to the pojo that contains hibernate/jpa annotations.
注意,基于注解的 configuration 可能会根据 hibernate 的版本而有所不同,并且可能需要额外的库.
note, annotation based configuration might be different depending on version of hibernate and may require additional libraries.