hibernate 异常解决方法

来源:互联网 发布:江阴网络诈骗判刑案例 编辑:程序博客网 时间:2024/05/22 10:50
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource Student.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:588)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1606)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1574)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1553)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1527)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1447)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1433)
at com.litsoft.hibernate.CreatTable.main(CreatTable.java:9)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:527)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:585)
... 7 more
Caused by: org.dom4j.DocumentException: Error on line 14 of document  : Element type "one-to-one" must be followed by either attribute specifications, ">" or "/>". Nested exception: Element type "one-to-one" must be followed by either attribute specifications, ">" or "/>".
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:518)

... 8 more


这个异常很普遍其实就是hbm文件的书写格式没有写对 也许你的hbm文件一点错误都没有但就是运行报错,最后找到了错误的原因


<one-to-one  name="idCard"    class="com.litsoft.hibernate.IdCard"   
cascade="all    "fetch="select"    />


在添加<one-to-one><many-to-one>这些标签的时候设置里面的属性时一定要留开空格不然肯定报错







0 0
原创粉丝点击