| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 3171 人关注过本帖
标题:【新手求助】hibernate4问题
只看楼主 加入收藏
lljwdbklb
Rank: 2
等 级:论坛游民
帖 子:24
专家分:47
注 册:2011-9-18
结帖率:100%
  已结贴   问题点数:20  回复次数:3   
【新手求助】hibernate4问题
我从帮助文档copy下来的xml配置文件,居然出错。想问下各位大神能不能解答我的问题。

程序代码:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration 
xmlns="http://www. 
xsi:schemaLocation="http://www. hibernate-configuration-4.0.xsd" 
xmlns:xsi="http://www. <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://192.168.1.102:3306/hibernate</property>
    <property name="connection.username">root</property>
    <property name="connection.password">25358318</property>

    <!-- JDBC connection pool (use the built-in) -->
    <!-- <property name="connection.pool_size">1</property> -->

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <!-- <property name="hbm2ddl.auto">update</property> -->
    <mapping resource="com/jun/hibernate/bean/Student.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


四月 18, 2013 10:43:57 下午 org.hibernate. <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
四月 18, 2013 10:43:57 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.0.Final}
四月 18, 2013 10:43:57 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
四月 18, 2013 10:43:57 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
四月 18, 2013 10:43:57 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
四月 18, 2013 10:43:57 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Exception in thread "main" org.hibernate.MappingException: invalid configuration
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2018)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1935)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1914)
    at StudentTest.main(StudentTest.java:16)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 25; 文档无效: 找不到语法。
    at com.(ErrorHandlerWrapper.java:198)
    at com.(ErrorHandlerWrapper.java:134)
    at com.(XMLErrorReporter.java:437)
    at com.(XMLErrorReporter.java:368)
    at com.(XMLErrorReporter.java:325)
    at com.(XMLNSDocumentScannerImpl.java:226)
    at com.(XMLNSDocumentScannerImpl.java:602)
    at com.(XMLDocumentFragmentScannerImpl.java:3065)
    at com.(XMLDocumentScannerImpl.java:881)
    at com.(XMLDocumentScannerImpl.java:607)
    at com.(XMLNSDocumentScannerImpl.java:116)
    at com.(XMLDocumentFragmentScannerImpl.java:489)
    at com.(XML11Configuration.java:835)
    at com.(XML11Configuration.java:764)
    at com.(XMLParser.java:123)
    at com.(AbstractSAXParser.java:1210)
    at com.(SAXParserImpl.java:568)
    at org.(SAXReader.java:465)
    at org.hi
搜索更多相关主题的帖子: xml property settings version 
2013-04-18 22:50
hhwz
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:87
帖 子:685
专家分:4475
注 册:2011-5-22
  得分:20 
StudentTest.main(StudentTest.java:16)
看看这里
2013-04-19 00:00
lljwdbklb
Rank: 2
等 级:论坛游民
帖 子:24
专家分:47
注 册:2011-9-18
  得分:0 
回复 2楼 hhwz
程序代码:
 
Configuration cfg = new Configuration();
cfg.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
SessionFactory sf = cfg.buildSessionFactory(serviceRegistry);
Session session = sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sf.close();


上面出错的代码是
cfg.configure();
2013-04-19 10:31
lljwdbklb
Rank: 2
等 级:论坛游民
帖 子:24
专家分:47
注 册:2011-9-18
  得分:0 
回复 2楼 hhwz
我已经自己找到问题所在了··是我看错hibernate的文档了
谢谢你的回答。
2013-04-19 20:41
快速回复:【新手求助】hibernate4问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.063825 second(s), 8 queries.
Copyright©2004-2020, BCCN.NET, All Rights Reserved