浏览 4329 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2004-05-16
http://www.loveunix.net/index.php?showtopic=7804 运行成功!现在我想将此例子用 JBuilder9 + hibernate2.1 + mysql 来运行,服务器用JBuilder9自带的Tomcat4.1 但是总是失败!我用JBuilder9来运行,已经弄了两天了,其间出现过一系列小错误,都已经纠正过来。而且在 JBuilder9 + hibernate2.1 + mysql 和 Tomcat5.0 + hibernate2.1 + UltraEdit + mysql 两种配置下,程序的代码都一模一样,只是配置文件稍有不同!所以问题症结应该在这里。 在 Tomcat5.0 + hibernate2.1 + UltraEdit + mysql 配置下的配置文件分别如下: tomcat5\conf\server.xml中加了如下语句: <!-- ************************* MY OWN *************************** --> <Context path="/hibernate" docBase="hibernate"> <Resource name="jdbc/hibernate" scope="Shareable" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/hibernate"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <!-- DBCP database connection settings --> <parameter> <name>url</name> <value>jdbc:mysql://localhost/test</value> </parameter> <parameter> <name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value> </parameter> <parameter> <name>username</name> <value>root</value> </parameter> <parameter> <name>password</name> <value>yang900</value> </parameter> <!-- DBCP connection pooling options --> <parameter> <name>maxWait</name> <value>3000</value> </parameter> <parameter> <name>maxIdle</name> <value>100</value> </parameter> <parameter> <name>maxActive</name> <value>10</value> </parameter> </ResourceParams> </Context> <!-- *************** MY OWN ******************* --> WEB-INF\classes\Course.hbm.xml文件如下: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.hellking.study.hibernate.Course" table="Courses" dynamic-update="false" > <id name="id" column="CourseId" type="string" unsaved-value="any" > <generator class="assigned"/> </id> <property name="name" type="string" update="true" insert="true" column="Name" /> </class> </hibernate-mapping> WEB-INF\classes\hibernate.cfg.xml文件如下: <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.datasource">java:comp/env/jdbc/hibernate</property> <property name="show_sql">false</property> <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property> <!-- Mapping files --> <mapping resource="Course.hbm.xml"/> </session-factory> </hibernate-configuration> 在 JBuilder9 + hibernate2.1 + mysql 配置下的配置文件分别如下: WEB-INF\classes\hibernate.properties 文件如下: hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N' hibernate.connection.datasource java:comp/env/jdbc/hibernate ## MySQL hibernate.dialect net.sf.hibernate.dialect.MySQLDialect hibernate.connection.driver_class org.gjt.mm.mysql.Driver hibernate.connection.url jdbc:mysql://localhost/test hibernate.connection.username root hibernate.connection.password yang900 hibernate.connection.pool_size 1 hibernate.proxool.pool_alias pool1 hibernate.show_sql false hibernate.jdbc.batch_size 0 hibernate.jdbc.use_streams_for_binary true hibernate.max_fetch_depth 1 hibernate.cache.use_query_cache true hibernate.session_factory_name org.apache.commons.dbcp.BasicDataSourceFactory WEB-INF\classes\Course.hbm.xml文件如下: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.hellking.study.hibernate.Course" table="Courses" dynamic-update="false" > <id name="id" column="CourseId" type="string" unsaved-value="any" > <generator class="assigned"/> </id> <property name="name" type="string" update="true" insert="true" column="Name" /> </class> </hibernate-mapping> 此时运行,错误信息如下: 2004-5-16 13:51:51 net.sf.hibernate.cfg.Environment <clinit> 信息: Hibernate 2.1.2 2004-5-16 13:51:51 net.sf.hibernate.cfg.Environment <clinit> 信息: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hibernate.session_factory_name=org.apache.commons.dbcp.BasicDataSourceFactory, hibernate.connection.datasource=java:comp/env/jdbc/hibernate, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.show_sql=false, hibernate.connection.password=yang900, hibernate.connection.pool_size=1} 2004-5-16 13:51:51 net.sf.hibernate.cfg.Environment <clinit> 信息: using java.io streams to persist binary types 2004-5-16 13:51:51 net.sf.hibernate.cfg.Environment <clinit> 信息: using CGLIB reflection optimizer 2004-5-16 13:51:51 net.sf.hibernate.cfg.Configuration configure 信息: configuring from resource: /hibernate.cfg.xml 2004-5-16 13:51:51 net.sf.hibernate.cfg.Configuration getConfigurationInputStream 信息: Configuration resource: /hibernate.cfg.xml 2004-5-16 13:51:51 net.sf.hibernate.cfg.Configuration getConfigurationInputStream 警告: /hibernate.cfg.xml not found StandardWrapperValve[debugjsp]: Servlet.service(); for servlet debugjsp threw exception javax.servlet.ServletException: class com.hellking.study.hibernate.CourseBean : net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found javax.servlet.ServletException: class com.hellking.study.hibernate.CourseBean : net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471); at org.apache.jsp.course$jsp._jspService(course$jsp.java:173); at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107); at javax.servlet.http.HttpServlet.service(HttpServlet.java:853); at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201); at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381); at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473); at javax.servlet.http.HttpServlet.service(HttpServlet.java:853); at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247); at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193); at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347); at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027); at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125); at java.lang.Thread.run(Thread.java:536); 我的分析: 由于出现“/hibernate.cfg.xml not found”错误,所以我就将hibernate.cfg.xml文件也放到WEB-INF\classes\下面,使之与文件WEB-INF\classes\hibernate.properties在JBuilder9下共存,文件内容分别如下: WEB-INF\classes\hibernate.cfg.xml文件: <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.datasource">java:comp/env/jdbc/hibernate</property> <property name="show_sql">false</property> <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property> <!-- Mapping files --> <mapping resource="Course.hbm.xml"/> </session-factory> </hibernate-configuration> WEB-INF\classes\hibernate.properties文件: hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N' ## MySQL #hibernate.dialect net.sf.hibernate.dialect.MySQLDialect hibernate.connection.driver_class org.gjt.mm.mysql.Driver hibernate.connection.url jdbc:mysql://localhost/test hibernate.connection.username root hibernate.connection.password yang900 hibernate.connection.pool_size 1 hibernate.proxool.pool_alias pool1 hibernate.jdbc.batch_size 0 hibernate.jdbc.use_streams_for_binary true hibernate.max_fetch_depth 1 hibernate.cache.use_query_cache true hibernate.cache.provider_class net.sf.hibernate.cache.HashtableCacheProvider hibernate.session_factory_name org.apache.commons.dbcp.BasicDataSourceFactory 此时再运行,出错信息如下: 2004-5-16 14:15:57 net.sf.hibernate.cfg.Environment <clinit> 信息: Hibernate 2.1.2 2004-5-16 14:15:57 net.sf.hibernate.cfg.Environment <clinit> 信息: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hibernate.session_factory_name=org.apache.commons.dbcp.BasicDataSourceFactory, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.connection.password=yang900, hibernate.connection.pool_size=1} 2004-5-16 14:15:57 net.sf.hibernate.cfg.Environment <clinit> 信息: using java.io streams to persist binary types 2004-5-16 14:15:57 net.sf.hibernate.cfg.Environment <clinit> 信息: using CGLIB reflection optimizer 2004-5-16 14:15:57 net.sf.hibernate.cfg.Configuration configure 信息: configuring from resource: /hibernate.cfg.xml 2004-5-16 14:15:57 net.sf.hibernate.cfg.Configuration getConfigurationInputStream 信息: Configuration resource: /hibernate.cfg.xml 2004-5-16 14:15:58 net.sf.hibernate.cfg.Configuration addResource 信息: Mapping resource: Course.hbm.xml 2004-5-16 14:15:58 net.sf.hibernate.cfg.Binder bindRootClass 信息: Mapping class: com.hellking.study.hibernate.Course -> Courses 2004-5-16 14:15:58 net.sf.hibernate.cfg.Configuration doConfigure 信息: Configured SessionFactory: null 2004-5-16 14:15:59 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-many association mappings 2004-5-16 14:15:59 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-one association property references 2004-5-16 14:15:59 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing foreign key constraints 2004-5-16 14:15:59 net.sf.hibernate.dialect.Dialect <init> 信息: Using dialect: net.sf.hibernate.dialect.MySQLDialect 2004-5-16 14:15:59 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Maximim outer join fetch depth: 1 2004-5-16 14:15:59 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use outer join fetching: true 2004-5-16 14:15:59 net.sf.hibernate.util.NamingHelper getInitialContext 信息: JNDI InitialContext properties:{} 2004-5-16 14:15:59 net.sf.hibernate.connection.DatasourceConnectionProvider configure 严重: Could not find datasource: java:comp/env/jdbc/hibernate javax.naming.NameNotFoundException: Name jdbc is not bound in this Context at org.apache.naming.NamingContext.lookup(NamingContext.java:811); at org.apache.naming.NamingContext.lookup(NamingContext.java:181); at org.apache.naming.NamingContext.lookup(NamingContext.java:822); at org.apache.naming.NamingContext.lookup(NamingContext.java:181); at org.apache.naming.NamingContext.lookup(NamingContext.java:822); at org.apache.naming.NamingContext.lookup(NamingContext.java:194); at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183); at javax.naming.InitialContext.lookup(InitialContext.java:347); at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44); at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83); at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:64); at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1119); at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:748); at com.hellking.study.hibernate.HibernateBase.initHibernate(HibernateBase.java:24); at com.hellking.study.hibernate.HibernateBase.<init>(HibernateBase.java:17); at com.hellking.study.hibernate.CourseBean.<init>(CourseBean.java:14); at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method); at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39); at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27); at java.lang.reflect.Constructor.newInstance(Constructor.java:274); at java.lang.Class.newInstance0(Class.java:306); at java.lang.Class.newInstance(Class.java:259); at java.beans.Beans.instantiate(Beans.java:204); at java.beans.Beans.instantiate(Beans.java:48); at org.apache.jsp.course$jsp._jspService(course$jsp.java:114); at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107); at javax.servlet.http.HttpServlet.service(HttpServlet.java:853); at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201); at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381); at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473); at javax.servlet.http.HttpServlet.service(HttpServlet.java:853); at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247); at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193); at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347); at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027); at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125); at java.lang.Thread.run(Thread.java:536); StandardWrapperValve[debugjsp]: Servlet.service(); for servlet debugjsp threw exception javax.servlet.ServletException: class com.hellking.study.hibernate.CourseBean : net.sf.hibernate.HibernateException: Could not find datasource javax.servlet.ServletException: class com.hellking.study.hibernate.CourseBean : net.sf.hibernate.HibernateException: Could not find datasource at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471); at org.apache.jsp.course$jsp._jspService(course$jsp.java:173); at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107); at javax.servlet.http.HttpServlet.service(HttpServlet.java:853); at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201); at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381); at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473); at javax.servlet.http.HttpServlet.service(HttpServlet.java:853); at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247); at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193); at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347); at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174); at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566); at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472); at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943); at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027); at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125); at java.lang.Thread.run(Thread.java:536); 我觉得问题应该出现在两个地方: 1)在 Tomcat5.0 + hibernate2.1 + UltraEdit + mysql 配置下,在tomcat5\conf\server.xml 中要加一些语句,比如数据库驱动相关配置项,如下: <parameter> <name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value> </parameter> <parameter> <name>username</name> <value>root</value> </parameter> <parameter> <name>password</name> <value>yang900</value> </parameter> 而这些语句在 JBuilder9 + hibernate2.1 + mysql 下的文件hibernate.properties中基本都有对应项,例如上面的语句在hibernate.properties对应为: ## MySQL #hibernate.dialect net.sf.hibernate.dialect.MySQLDialect hibernate.connection.driver_class org.gjt.mm.mysql.Driver hibernate.connection.url jdbc:mysql://localhost/test hibernate.connection.username root hibernate.connection.password yang900 但是如下项在文件hibernate.properties中是没有对应项的: <Context path="/hibernate" docBase="hibernate"> <Resource name="jdbc/hibernate" scope="Shareable" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/hibernate"> <parameter> 又由于JBuilder9下的Tomcat和单独运行Tomcat机制不一样,所以不能在JBuilder9自带的Tomcat4.1\conf\server.xml中加入相关配置项。我认为这是主要问题。 2)是文件 hibernate.properties 和文件 hibernate.cfg.xml 之间的区别: hibernate.cfg.xml文件中有如下项: <mapping resource="Course.hbm.xml"/> 而在文件 hibernate.properties 中没有对应项。 另:肯定不是Tomcat版本的问题,因为我在 Tomcat5.0 + hibernate2.1 + UltraEdit + mysql Tomcat4.1 + hibernate2.1 + UltraEdit + mysql 两钟配置下运行此例都成功! 诚请各位大侠帮我解答,本人感激不尽!!! 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2004-05-17
问题很明显啊,你的datasource设错了。我从未用过Jbuilder,但是问题肯定在这一行:
WEB-INF\classes\hibernate.cfg.xml文件: <property name="connection.datasource">java:comp/env/jdbc/hibernate</property> 试着把其中的内容换成你真正的datasource name,比如jdbc/hibernate,再试。 |
|
返回顶楼 | |
发表时间:2004-05-17
不是这个问题,我按你说的改了,也不好使。后来,我改了两处:
1)在配置文件hibernate.properties中将 hibernate.connection.datasource java:comp/env/jdbc/hibernate 注释掉. 2)将HibernateBase.java文件中的 sessionFactory = new Configuration();.configure();.buildSessionFactory();; 改为 sessionFactory = new Configuration();.buildSessionFactory();; 结果能运行了,但是不能成功插入数据,也不出现错误,服务器信息如下: 2004-5-17 13:52:07 net.sf.hibernate.cfg.Environment <clinit> 信息: Hibernate 2.1.2 2004-5-17 13:52:07 net.sf.hibernate.cfg.Environment <clinit> 信息: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hibernate.session_factory_name=org.apache.commons.dbcp.BasicDataSourceFactory, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.show_sql=false, hibernate.connection.password=yang900, hibernate.connection.pool_size=1} 2004-5-17 13:52:07 net.sf.hibernate.cfg.Environment <clinit> 信息: using java.io streams to persist binary types 2004-5-17 13:52:07 net.sf.hibernate.cfg.Environment <clinit> 信息: using CGLIB reflection optimizer 2004-5-17 13:52:07 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-many association mappings 2004-5-17 13:52:07 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-one association property references 2004-5-17 13:52:07 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing foreign key constraints 2004-5-17 13:52:07 net.sf.hibernate.dialect.Dialect <init> 信息: Using dialect: net.sf.hibernate.dialect.MySQLDialect 2004-5-17 13:52:07 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Maximim outer join fetch depth: 1 2004-5-17 13:52:07 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use outer join fetching: true 2004-5-17 13:52:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: Using Hibernate built-in connection pool (not for production use!); 2004-5-17 13:52:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: Hibernate connection pool size: 1 2004-5-17 13:52:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/test 2004-5-17 13:52:07 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: connection properties: {user=root, password=yang900} 2004-5-17 13:52:07 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup 信息: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended); 2004-5-17 13:52:09 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use scrollable result sets: true 2004-5-17 13:52:09 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use JDBC3 getGeneratedKeys();: true 2004-5-17 13:52:09 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Optimize cache for minimal puts: false 2004-5-17 13:52:09 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Query language substitutions: {no='N', true=1, yes='Y', false=0} 2004-5-17 13:52:09 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: cache provider: net.sf.hibernate.cache.HashtableCacheProvider 2004-5-17 13:52:09 net.sf.hibernate.cfg.Configuration configureCaches 信息: instantiating and configuring caches 2004-5-17 13:52:09 net.sf.hibernate.impl.SessionFactoryImpl <init> 信息: building session factory 2004-5-17 13:52:09 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance 信息: Factory name: org.apache.commons.dbcp.BasicDataSourceFactory 2004-5-17 13:52:09 net.sf.hibernate.util.NamingHelper getInitialContext 信息: JNDI InitialContext properties:{} 2004-5-17 13:52:09 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance 信息: Bound factory to JNDI name: org.apache.commons.dbcp.BasicDataSourceFactory 2004-5-17 13:52:09 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance 警告: InitialContext did not implement EventContext 2004-5-17 13:52:09 net.sf.hibernate.cache.UpdateTimestampsCache <init> 信息: starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache 2004-5-17 13:52:10 net.sf.hibernate.cache.QueryCache <init> 信息: starting query cache at region: net.sf.hibernate.cache.QueryCache 2004-5-17 13:52:15 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-many association mappings 2004-5-17 13:52:15 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-one association property references 2004-5-17 13:52:15 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing foreign key constraints 2004-5-17 13:52:15 net.sf.hibernate.dialect.Dialect <init> 信息: Using dialect: net.sf.hibernate.dialect.MySQLDialect 2004-5-17 13:52:15 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Maximim outer join fetch depth: 1 2004-5-17 13:52:15 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use outer join fetching: true 2004-5-17 13:52:15 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: Using Hibernate built-in connection pool (not for production use!); 2004-5-17 13:52:15 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: Hibernate connection pool size: 1 2004-5-17 13:52:15 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/test 2004-5-17 13:52:15 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: connection properties: {user=root, password=yang900} 2004-5-17 13:52:15 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup 信息: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended); 2004-5-17 13:52:15 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use scrollable result sets: true 2004-5-17 13:52:15 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use JDBC3 getGeneratedKeys();: true 2004-5-17 13:52:15 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Optimize cache for minimal puts: false 2004-5-17 13:52:15 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Query language substitutions: {no='N', true=1, yes='Y', false=0} 2004-5-17 13:52:15 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: cache provider: net.sf.hibernate.cache.HashtableCacheProvider 2004-5-17 13:52:15 net.sf.hibernate.cfg.Configuration configureCaches 信息: instantiating and configuring caches 2004-5-17 13:52:15 net.sf.hibernate.impl.SessionFactoryImpl <init> 信息: building session factory 2004-5-17 13:52:15 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance 信息: Factory name: org.apache.commons.dbcp.BasicDataSourceFactory 2004-5-17 13:52:15 net.sf.hibernate.util.NamingHelper getInitialContext 信息: JNDI InitialContext properties:{} 2004-5-17 13:52:15 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance 信息: Bound factory to JNDI name: org.apache.commons.dbcp.BasicDataSourceFactory 2004-5-17 13:52:15 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance 警告: InitialContext did not implement EventContext 2004-5-17 13:52:15 net.sf.hibernate.cache.UpdateTimestampsCache <init> 信息: starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache 2004-5-17 13:52:15 net.sf.hibernate.cache.QueryCache <init> 信息: starting query cache at region: net.sf.hibernate.cache.QueryCache |
|
返回顶楼 | |
发表时间:2004-05-17
需要在JB中配置一个DataSource类似在Server.xml中的有关配置一样,不过在JB 中需要一个mod.jar文件,如果需要,留下你的MSN我可以传给你
|
|
返回顶楼 | |
发表时间:2004-05-18
我的邮箱: brawniness@tom.com
谢谢!!! |
|
返回顶楼 | |