首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

hibernate实体类配置文件,该怎么处理

2012-01-20 
hibernate实体类配置文件?xml version1.0 encodingUTF-8?!DOCTYPE hibernate-mapping PUBLIC-//

hibernate实体类配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="inherit_tph">
<class name="Computer" table="computer_tph">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>
<property name="manufactory" column="manufactory" type="string"/>
<property name="price" column="price" type="double"/>
<discriminator column="catagory" type="character"/>
<subclass name="Notepad" discriminator-value="n">
<property name="weight" column="weight" type="double"/>
<property name="thickness" column="thickness" type="double"/>
</subclass>
<subclass name="Desktop" discriminator-value="d">
<property name="LCD" column="islcd" type="yes_no"/>
</subclass>
</class>
</hibernate-mapping>

Could not parse mapping document from resource inherit_tph/computer.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at util.HibernateUtil.<clinit>(HibernateUtil.java:13)
at inherit_tph.ComputerService.find(ComputerService.java:117)
at inherit_tph.Test.main(Test.java:47)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:549)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 9 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".

上面提示class不匹配,但是我实在找不出哪里出问题了,各位帮忙看看!

[解决办法]
将Computer变成非抽象类进行映射,类代码如下

Java code
public class Computer {    private int id;    private double price;    private String manufactory;        //需要空的构造函数    public Computer(){}        public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public double getPrice() {        return price;    }    public void setPrice(double price) {        this.price = price;    }    public String getManufactory() {        return manufactory;    }    public void setManufactory(String manufactory) {        this.manufactory = manufactory;    }        } 

热点排行