org.hibernate.InvalidMappingException: Could not parse mapping document from file hibernate.cfg.xml
org.hibernate.cfg.Configuration.addFile(Configuration.java:291)
com.test.action.LoginAction.execute(LoginAction.java:34)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
控制台的
信息: Server startup in 1727 ms
11625 [http-8081-2] INFO cfg.Environment - Hibernate 3.2.0
11625 [http-8081-2] INFO cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.connection.password=****, hibernate.c3p0.acquire_increment=2, hibernate.c3p0.idle_test_period=1000, hibernate.show_sql=false, hibernate.c3p0.checkoutTimeout=40000, hibernate.c3p0.max_statements=200, hibernate.jdbc.batch_size=25, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.fetch_size=25, hibernate.c3p0.validate=false, hibernate.c3p0.timeout=120, hibernate.c3p0.min_size=0, hibernate.format_sql=false, hibernate.connection.username=root, hibernate.transaction.auto_close_session=true, hibernate.connection.driver_class=com.mysql.jdbc.ReplicationDriver, hibernate.current_session_context_class=thread, hibernate.c3p0.max_size=10, hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider, hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/logindb?characterEncoding=gb2312}
11625 [http-8081-2] INFO cfg.Environment - Bytecode provider name : cglib
11640 [http-8081-2] INFO cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
11750 [http-8081-2] INFO cfg.Configuration - configuring from resource: /hibernate.cfg.xml
11750 [http-8081-2] INFO cfg.Configuration - Configuration resource: /hibernate.cfg.xml
11859 [http-8081-2] INFO cfg.Configuration - Reading mappings from resource: com/test/model/logindb.hbm.xml
11984 [http-8081-2] INFO cfg.HbmBinder - Mapping class: com.test.action.LoginAction -> customer
12015 [http-8081-2] INFO cfg.Configuration - Configured SessionFactory: null
12015 [http-8081-2] INFO cfg.Configuration - Reading mappings from file: hibernate.cfg.xml/practice/src/hibernate.cfg.xml:<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<!--Examda提示:数据库用户名-->
<property name="connection.username">root</property>
<!--数据库URL-->
<property name="connection.url">
jdbc:mysql://localhost:3306/logindb
</property>
<!--dialect,每个数据库对应的Dialet匹配其平台特性-->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!--数据库密码-->
<property name="connection.password">0</property>
<!--数据库驱动-->
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.use_out_join">True</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acqiure_increment">2</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/test/model/logindb.hbm.xml" />
</session-factory>
</hibernate-configuration>logindb.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">
<hibernate-mapping>
<class name="com.test.action.LoginAction" table="customer">
<id name="customerId" type="string" column="customerId">
<generator class="identity" />
</id>
<property name="customerId" type="string">
<column name="customerId" length="10" />
</property>
<property name="password" type="string">
<column name="password" length="20" />
</property>
</class>
</hibernate-mapping>action: Configuration conf = new Configuration().configure().addFile("hibernate.cfg.xml");
SessionFactory sf = conf.buildSessionFactory();
Session sess = sf.openSession();
Transaction tx = sess.beginTransaction();
走到第一行就异常。
为什么会有异常呢?本人初学者,望各路神灵指点
org.hibernate.cfg.Configuration.addFile(Configuration.java:291)
com.test.action.LoginAction.execute(LoginAction.java:34)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
控制台的
信息: Server startup in 1727 ms
11625 [http-8081-2] INFO cfg.Environment - Hibernate 3.2.0
11625 [http-8081-2] INFO cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.connection.password=****, hibernate.c3p0.acquire_increment=2, hibernate.c3p0.idle_test_period=1000, hibernate.show_sql=false, hibernate.c3p0.checkoutTimeout=40000, hibernate.c3p0.max_statements=200, hibernate.jdbc.batch_size=25, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.fetch_size=25, hibernate.c3p0.validate=false, hibernate.c3p0.timeout=120, hibernate.c3p0.min_size=0, hibernate.format_sql=false, hibernate.connection.username=root, hibernate.transaction.auto_close_session=true, hibernate.connection.driver_class=com.mysql.jdbc.ReplicationDriver, hibernate.current_session_context_class=thread, hibernate.c3p0.max_size=10, hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider, hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/logindb?characterEncoding=gb2312}
11625 [http-8081-2] INFO cfg.Environment - Bytecode provider name : cglib
11640 [http-8081-2] INFO cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
11750 [http-8081-2] INFO cfg.Configuration - configuring from resource: /hibernate.cfg.xml
11750 [http-8081-2] INFO cfg.Configuration - Configuration resource: /hibernate.cfg.xml
11859 [http-8081-2] INFO cfg.Configuration - Reading mappings from resource: com/test/model/logindb.hbm.xml
11984 [http-8081-2] INFO cfg.HbmBinder - Mapping class: com.test.action.LoginAction -> customer
12015 [http-8081-2] INFO cfg.Configuration - Configured SessionFactory: null
12015 [http-8081-2] INFO cfg.Configuration - Reading mappings from file: hibernate.cfg.xml/practice/src/hibernate.cfg.xml:<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<!--Examda提示:数据库用户名-->
<property name="connection.username">root</property>
<!--数据库URL-->
<property name="connection.url">
jdbc:mysql://localhost:3306/logindb
</property>
<!--dialect,每个数据库对应的Dialet匹配其平台特性-->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!--数据库密码-->
<property name="connection.password">0</property>
<!--数据库驱动-->
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.use_out_join">True</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acqiure_increment">2</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/test/model/logindb.hbm.xml" />
</session-factory>
</hibernate-configuration>logindb.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">
<hibernate-mapping>
<class name="com.test.action.LoginAction" table="customer">
<id name="customerId" type="string" column="customerId">
<generator class="identity" />
</id>
<property name="customerId" type="string">
<column name="customerId" length="10" />
</property>
<property name="password" type="string">
<column name="password" length="20" />
</property>
</class>
</hibernate-mapping>action: Configuration conf = new Configuration().configure().addFile("hibernate.cfg.xml");
SessionFactory sf = conf.buildSessionFactory();
Session sess = sf.openSession();
Transaction tx = sess.beginTransaction();
走到第一行就异常。
为什么会有异常呢?本人初学者,望各路神灵指点
解决方案 »
- 有没有查看web服务器性能和连接数、连接状态的工具
- 关于java做管理系统的权限
- session丢失
- [求助]一个关于jdom包报错的问题
- Cannot find class [lee.LoginAcion] for bean with name '/login' defined in ServletContext resource [/WEB-INF/applicationContext.x
- 怎样把jsp留言发送到电子邮箱中?
- 一个ant小问题,运行jar需要外部包,谢谢!
- 用dreamweaver开发jsp编程,这两句是什么意思?谢谢。
- 关于tomcat5数据库连接池的配置问题!
- 如何响应
- java 获取Mac地址,以及ip
- structs2 上传图片的问题 。 firfox 可以 而ie8 不可以?
<property name="name" column="name" type="java.lang.String" not-null="true" />
LoginAction 对应customer 不对吧?
表customer对应的应该是一个javaBean对象啊!
我给改成这个了
<class name="com.test.model.Login" table="customer">javabean:package com.test.model;public class Login { private String customerId;
private String password;
public void setPassword(String password) {
this.password = password;
} public String getPassword() {
return password;
} public void setCustomerId(String customerId) {
this.customerId = customerId;
} public String getCustomerId() {
return customerId;
}}还是报一样的异常
hibernate.cfg.xml路径有问题吧?!自己好好查一查吧