新手Hibernate 映射文件问题。。。。

bobo5211988 2011-12-05 12:35:02
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-mapping>
<class name="com.test.set.Users" table="USERS" schema="test1">
<id name="id" column="ID" type="int">
<generator class="increment"/>
</id>
<property name="username" type="java.lang.String">
<column name="NAME" length="50"></column>
</property>
<property name="age" type="int">
<column name="AGE"/>
</property>
<set name="images" table="IMAGES" lazy="true">
<key column="USERID"/>
<element column="FILENAME" type="string" not-null="true"/>
</set>
</class>
</hibernate-mapping>
为什么property行会报错multiple markers at this line -Attribute''type'' must be declared for element type "property"
运行后抛异常
Exception in thread "main" org.hibernate.MappingException: Could not read mappings from resource: com/test/set/Users.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
at com.test.set.UsersDAO.<init>(UsersDAO.java:15)
at com.test.set.Test.main(Test.java:17)
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:425)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
... 8 more
Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422)
... 9 more
我用的是myeclipse
...全文
132 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
kouyiSC 2011-12-05
  • 打赏
  • 举报
回复
type类型错误。。。数据库ID为int,实体中可以是long类型
oO临时工Oo 2011-12-05
  • 打赏
  • 举报
回复
真有可能是integer
quhuafeng521 2011-12-05
  • 打赏
  • 举报
回复
映射文件中描述的类型可以是java类型:
Java.lang.Integer
或是hibernate类型 :integer
没有int
  • 打赏
  • 举报
回复
integer
阿诺 2011-12-05
  • 打赏
  • 举报
回复
com/test/set/Users.hbm.xml
是不是没有找到这个文件
看看:Caused by: 哪里说的什么异常!
http://zhidao.baidu.com/question/76005705.html 百度上!
bobo5211988 2011-12-05
  • 打赏
  • 举报
回复
我是按一个视频编的,他没错,不过他用的是eclipse,自己导的jar包,自己配置的
bobo5211988 2011-12-05
  • 打赏
  • 举报
回复
配置文件的Users还是?
kouyiSC 2011-12-05
  • 打赏
  • 举报
回复
将对象Users中的所有int型改为long就行了。。。
bobo5211988 2011-12-05
  • 打赏
  • 举报
回复
改成Integer了,不行,还是原来的错误!!

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧