初学者新手小菜求大神帮忙啊。。。。。。

oMarlboro123456 2013-01-23 10:13:23
hibernate.cfg.xml里面的代码
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="connection.url">
jdbc:sqlserver://localhost:1433
</property>
<property name="connection.username">sa</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="myeclipse.connection.profile">House</property>
<property name="show_sql">true</property>
<mapping resource="cn/jbit/bean/Users.hbm.xml" />

</session-factory>

</hibernate-configuration>
Users.hbm.xml里面的代码
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="cn.jbit.bean.Users" table="Users" schema="dbo" catalog="HouseRent">
<id name="id" type="integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="name" type="string">
<column name="name" not-null="true" />
</property>
<property name="password" type="string">
<column name="password" not-null="true" />
</property>
<property name="telephone" type="string">
<column name="telephone" not-null="true" />
</property>
<property name="username" type="string">
<column name="username" not-null="true" />
</property>
<property name="isadmin" type="string">
<column name="isadmin" length="10" not-null="true" />
</property>
</class>
</hibernate-mapping>

Tes.t.java里面的代码
package cn.jbit.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import cn.jbit.bean.Users;

public class Test {

/**
* @param args
*/
public static void main(String[] args)
{

/**
* @param args
*/


Configuration conf = new Configuration().configure();
SessionFactory sf =conf.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
Users users= new Users();

users.setName("zhangsan");
users.setPassword("12345");
users.setTelephone("123213");
users.setIsadmin("是");
users.setUsername("dfjdsj");
session.save(users);
tx.commit();
session.close();

}

}
一片惨红的代码
2013-1-23 10:02:25 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.4.Final}
2013-1-23 10:02:25 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
2013-1-23 10:02:25 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
2013-1-23 10:02:25 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
2013-1-23 10:02:25 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
2013-1-23 10:02:25 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: cn/jbit/bean/Users.hbm.xml
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
at org.hibernate.cfg.Configuration.add(Configuration.java:478)
at org.hibernate.cfg.Configuration.add(Configuration.java:474)
at org.hibernate.cfg.Configuration.add(Configuration.java:647)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:730)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2109)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2081)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2061)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2014)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1929)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1908)
at cn.jbit.test.Test.main(Test.java:23)
Caused by: org.dom4j.DocumentException: Error on line 3 of document : The system identifier must begin with either a single or double quote character. Nested exception: The system identifier must begin with either a single or double quote character.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
... 11 more
文件路径配置截图

求各位大神帮忙啊
...全文
265 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
BUG胡汉三 2013-01-23
  • 打赏
  • 举报
回复
好像你的dtd最后多了一个空格!
zchua174 2013-01-23
  • 打赏
  • 举报
回复
引用 4 楼 oMarlboro123456 的回复:
引用 1 楼 zchua174 的回复:Users.hbm.xml 配置文件有问题 ,仔细点写吧。 没问题阿,我用的是MyEclipse10.7+SQL2012,是不是我版本的问题啊
你不要它自动生成, 手动去弄 eclipse有时候很坑爹的
oMarlboro123456 2013-01-23
  • 打赏
  • 举报
回复
引用 11 楼 hzw2312 的回复:
加载hibernate.cfg.xml的时候说你的hbm.xml找不到指定的文件! 你得换一个3楼给出的dtd
Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-configuration", must match DOCTYPE root "hibernate-mapping". 现在变成介个了。。。
oMarlboro123456 2013-01-23
  • 打赏
  • 举报
回复
引用 10 楼 AA5279AA 的回复:
4.1.? 几? 4.1.8 不让用buildSessionFactory() 方法了 这是4.1.8之后的方法: public static void main(String[] args) { Student s=new Student(); s.setId(1); s.setNam……
4.1.4依旧惨红,可怜这个菜了
BUG胡汉三 2013-01-23
  • 打赏
  • 举报
回复
加载hibernate.cfg.xml的时候说你的hbm.xml找不到指定的文件! 你得换一个3楼给出的dtd
失落夏天 2013-01-23
  • 打赏
  • 举报
回复
4.1.? 几? 4.1.8 不让用buildSessionFactory() 方法了 这是4.1.8之后的方法: public static void main(String[] args) { Student s=new Student(); s.setId(1); s.setName("penglei"); s.setAge(25); Configuration config=new Configuration().configure(); ServiceRegistry sr=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); SessionFactory sf=config.buildSessionFactory(sr); Session session=sf.openSession(); session.beginTransaction(); session.save(s); session.getTransaction().commit(); session.close(); sf.close(); } 最后发一下感叹,这是我半年前在CSDN上看到一个问题,半年后竟然能找到原帖子,百度真强大。!~
oMarlboro123456 2013-01-23
  • 打赏
  • 举报
回复
引用 8 楼 AA5279AA 的回复:
默认就是src下面的, 你hibernate的版本是多少? 我记得以前有人发过帖子,hiberntate的版本不同,加载方式不同。
hiberntate4.1
失落夏天 2013-01-23
  • 打赏
  • 举报
回复
默认就是src下面的, 你hibernate的版本是多少? 我记得以前有人发过帖子,hiberntate的版本不同,加载方式不同。
oMarlboro123456 2013-01-23
  • 打赏
  • 举报
回复
引用 3 楼 dw_java08 的回复:
异常信息:Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML 把下面的信息换成你的hbm.xml开头部分 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/H……
一片惨红啊
oMarlboro123456 2013-01-23
  • 打赏
  • 举报
回复
引用 2 楼 AA5279AA 的回复:
hibernate.cfg.xml 这个文件你放在哪个目录下面的?
src下面啊
BUG胡汉三 2013-01-23
  • 打赏
  • 举报
回复
创建Configuration对象的时候、传入你配置文件的路径:
Configuration conf = new Configuration().configure("/hibernate.cfg.xml");
oMarlboro123456 2013-01-23
  • 打赏
  • 举报
回复
引用 1 楼 zchua174 的回复:
Users.hbm.xml 配置文件有问题 ,仔细点写吧。
没问题阿,我用的是MyEclipse10.7+SQL2012,是不是我版本的问题啊
dw_java08 2013-01-23
  • 打赏
  • 举报
回复
异常信息:Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML 把下面的信息换成你的hbm.xml开头部分 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
失落夏天 2013-01-23
  • 打赏
  • 举报
回复
hibernate.cfg.xml 这个文件你放在哪个目录下面的?
zchua174 2013-01-23
  • 打赏
  • 举报
回复
Users.hbm.xml 配置文件有问题 ,仔细点写吧。
dw_java08 2013-01-23
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd "> 把中间的空格去掉。

81,122

社区成员

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

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