这是一个测试类
import org.hibernate.*;
import org.hibernate.cfg.*;public class Test
{
public static void main(String[] args)
{
try
{
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
for (int i = 0; i <200; i++)
{
Customer customer = new Customer();
customer.setUsername("customer" + i);
customer.setPassword("customer");
session.save(customer);
}
tx.commit();
session.close();
}
catch (HibernateException e)
{
e.printStackTrace();
}
}
}
该类编译的结果和上一类编译的结果在同一目录src下(即有d:\test\src\test.class和d:\test\src\Customer .class)按例子上所述我将hibernate.jar和hibernate包下的lib包下的所有文件都放到了d:\test\lib下,在d:\test\db下我放了sqlserver的jdbc驱动文件
import org.hibernate.*;
import org.hibernate.cfg.*;public class Test
{
public static void main(String[] args)
{
try
{
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
for (int i = 0; i <200; i++)
{
Customer customer = new Customer();
customer.setUsername("customer" + i);
customer.setPassword("customer");
session.save(customer);
}
tx.commit();
session.close();
}
catch (HibernateException e)
{
e.printStackTrace();
}
}
}
该类编译的结果和上一类编译的结果在同一目录src下(即有d:\test\src\test.class和d:\test\src\Customer .class)按例子上所述我将hibernate.jar和hibernate包下的lib包下的所有文件都放到了d:\test\lib下,在d:\test\db下我放了sqlserver的jdbc驱动文件
解决方案 »
- 求解 EXTJS 3.0 这个错误:Uncaught TypeError: Cannot set property 'width' of undefined
- 没多少分了,小问题请教,java web的jsp+servlet+sql2000。
- SQL Server2005如何存储double类型?(急)
- JSP连接SQL 2000数据库
- JAVA求职的误区之第一篇(JAVA视频)
- 请高手介绍几个开源的java的 CMS组件 和 搜索组件?
- 页面中脚本运用DOM时如何找到脚本运行位置的父对象。没分了,以后补上吧。
- clob&blob问题,急???
- JSP传送数据到俄Excel文件的方法?
- 各位有碰到这种情况吗?
- 发布EJB时出现警告信息,不知何意.
- 能告诉我一个配置tomcat5.5+j2sdk1.4.2-07的简单的方法吗?只要能用就行了。
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping>
<class name="Customer" table="CUSTOMER">
<id name="id" column="CID">
<generator class="increment" />
</id>
<property name="username" column="USERNAME" />
<property name="password" column="PASSWORD" />
</class>
</hibernate-mapping>
和和hibernate.cfg.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory name="java:/hibernate/HibernateFactory"><property name="show_sql">true</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver <!-- ÕâÀïÊÇSqlserverµÄJDBC driver classÃû -->
</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=hibernate_test;SelectMethod=cursor <!-- ÕâÀïÊÇSqlserverµÄhibernate_testÊý¾Ý¿âURL -->
</property>
<property name="connection.username">
sa
</property>
<property name="connection.password">
ssssss
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect <!-- ÕâÀïÊÇsqlserverµÄDialect -->
</property>
<mapping resource="Customer.hbm.xml"/><-- Ö¸¶¨CustomerµÄÓ³ÉäÎļþ -->
</session-factory>
</hibernate-configuration>
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment
).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xm
l
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1279)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1218)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1204)
at Test.main(Test.java:10)
Caused by: org.dom4j.DocumentException: Error on line 26 of document : The cont
ent of elements must consist of well-formed character data or up. Nested exc
eption: The content of elements must consist of well-formed character data or ma
rkup.
at org.dom4j.io.SAXReader.read(SAXReader.java:355)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1274)
... 3 more我很痛苦,这个例子折腾了好长时间了,到底哪错了?
贴上来看看
把.class目录下的java文件去掉试试,或者是.class 的目录不对
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory name="java:/hibernate/HibernateFactory"><property name="show_sql">true</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver <!-- ÕâÀïÊÇSqlserverµÄJDBC driver classÃû -->
</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=hibernate_test;SelectMethod=cursor <!-- ÕâÀïÊÇSqlserverµÄhibernate_testÊý¾Ý¿âURL -->
</property>
<property name="connection.username">
sa
</property>
<property name="connection.password">
ssssss
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect <!-- ÕâÀïÊÇsqlserverµÄDialect -->
</property>
<mapping resource="Customer.hbm.xml"/><-- Ö¸¶¨CustomerµÄÓ³ÉäÎļþ -->
</session-factory>
</hibernate-configuration>