Re: Plea for help w/Struts-Hibernate Plugin that has it working!
Excellent I will give that a try. What I was hoping to do was maintain one JDNI location for my database, but I will definitly try this out. Thanks! -David - Original Message - From: David Friedman [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Tuesday, December 16, 2003 6:34 PM Subject: RE: Plea for help w/Struts-Hibernate Plugin that has it working! David, There is an alternative Struts/Hibernate/JNDI combination. All of it hinges on one file: hibernate.cfg.xml. It doesn't require any changes to server.xml or web.xml and works (at the very least) for me on Struts v1.0 v1.1 with Hibernate v2.0.3 V2.1beta6 under Tomcat 4.1.24 through 4.1.29. * Use a hibernate.cfg.xml file like so (passwords changed and pardon my MySQL slant) ?xml version='1.0' encoding='utf-8'? !DOCTYPE hibernate-configuration PUBLIC -//Hibernate/Hibernate Configuration DTD 2.0//EN http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd; hibernate-configuration session-factory name=dgf:/hibernate/SessionFactory property name=dialectnet.sf.hibernate.dialect.MySQLDialect/property property name=connection.usernameAA/property property name=connection.passwordBB/property property name=connection.urljdbc:mysql://localhost:3306/authors/property property name=connection.driver_classcom.mysql.jdbc.Driver/property property name=show_sqltrue/property property name=use_outer_jointrue/property property name=transaction.factory_classnet.sf.hibernate.transaction.JDBCTransactio nFactory/property property name=dbcp.minIdle1/property !-- Optional, I use this but it requires an opensymphony.org download of OSCache property name=cache.use_query_cachetrue/property property name=cache.provider_classnet.sf.hibernate.cache.OSCacheProvider/property -- !-- insert any mapping file so you don't need to hardcode adding classes or adding files in a Java class -- mapping resource=hibernate/Misc.hbm.xml/ /session-factory /hibernate-configuration The JNDI location is set in the session-factory tag using the 'name=' attribute. Whatever name you choose, DO NOT use anything starting java:comp/env as that is read-only in Tomcat and will NOT work. I made up a context named dgf:/hibernate/SessionFactory and was pleasantly surprised when hibernate created the context for me and stored the SessionFactory within it so I could us it in JNDI context lookups after I got the InitialContext and performed a ' SessionFactory sf = (SessionFactory) context.lookup(dgf:/hibernate/SessionFactory);'. I see you want to use DBCP. As long as you set a minimum of 1 dbcp property, hibernate will detect you want to use DBCP as your connection pool. Feel free to set more than one DBCP property or even to use something other than dbcp.minIdle as in my working example above. Hibernate can work with other connection pools. I recommend avoiding C3P0 as it can't shutdown (eats up memory unless you fully shutdown the JVM [i.e. TOMCAT] and restart). A Beta C3P0 allows shutdown of a C3P0 pool, but the last time I checked, the Hibernate controlling class for C3P0 pooling still had an empty finalize() and never actually shutdown my C3P0 pool. Regards, David -Original Message- From: David Erickson [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 16, 2003 7:20 PM To: Struts Mailing List Subject: Plea for help w/Struts-Hibernate Plugin that has it working! For some reason I just cannot make the Struts-Hibernate plugin work.. I can't make the Struts-Hibernate Listener work either. Here is the link to class I am trying to use: http://www.hibernate.org/133.html Here is the error I get without fail every time.. now note that this jndi connection WORKS fine when I use the HibernateUtil class, or when I use my own JDNI tests. Error: 2003-12-16 17:10:31,452 [DEBUG] impl.SessionImpl - opened session 2003-12-16 17:10:31,468 [DEBUG] transaction.JDBCTransaction - begin 2003-12-16 17:10:31,484 [DEBUG] util.JDBCExceptionReporter - SQL Exception java.sql.SQLException: Cannot load JDBC driver class 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.jav a:529) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:3 12) at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(Datas ourceConnectionProvider.java:59) at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:262) at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3155) at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3138) at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40) My setup: tomcat_home\common\lib contains: commons-dbcp.jar commons-pool.jar jdbc2_0-stdext.jar jndi.jar
Plea for help w/Struts-Hibernate Plugin that has it working!
For some reason I just cannot make the Struts-Hibernate plugin work.. I can't make the Struts-Hibernate Listener work either. Here is the link to class I am trying to use: http://www.hibernate.org/133.html Here is the error I get without fail every time.. now note that this jndi connection WORKS fine when I use the HibernateUtil class, or when I use my own JDNI tests. Error: 2003-12-16 17:10:31,452 [DEBUG] impl.SessionImpl - opened session 2003-12-16 17:10:31,468 [DEBUG] transaction.JDBCTransaction - begin 2003-12-16 17:10:31,484 [DEBUG] util.JDBCExceptionReporter - SQL Exception java.sql.SQLException: Cannot load JDBC driver class 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.jav a:529) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:3 12) at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(Datas ourceConnectionProvider.java:59) at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:262) at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3155) at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3138) at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40) My setup: tomcat_home\common\lib contains: commons-dbcp.jar commons-pool.jar jdbc2_0-stdext.jar jndi.jar mysql-connector-java-3.0.8-stable-bin.jar hibernate2.jar etc Server.xml: DefaultContext Resource name=jdbc/Salesweb auth=Container type=javax.sql.DataSource/ ResourceParams name=jdbc/Salesweb parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter parameter namemaxActive/name value100/value /parameter parameter namemaxIdle/name value30/value /parameter parameter namemaxWait/name value1/value /parameter parameter nameusername/name valuemyuser/value /parameter parameter namepassword/name valuemypass/value /parameter parameter namedriverClassName/name valueorg.gjt.mm.mysql.Driver/value /parameter parameter nameurl/name valuejdbc:mysql://192.168.0.104:3306/salesweb?autoReconnect=true/value /parameter /ResourceParams /DefaultContext web.xml: resource-ref descriptionSalesweb Database Connection/description res-ref-namejdbc/Salesweb/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref hibernate.cfg.xml: hibernate-configuration session-factory property name=connection.datasourcejava:comp/env/jdbc/Salesweb/property property name=show_sqltrue/property property name=dialectnet.sf.hibernate.dialect.MySQLDialect/property !-- Mapping files -- mapping resource=Prospect.hbm.xml/ /session-factory /hibernate-configuration Thanks for any help in advance!!! -David - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Plea for help w/Struts-Hibernate Plugin that has it working!
David, There is an alternative Struts/Hibernate/JNDI combination. All of it hinges on one file: hibernate.cfg.xml. It doesn't require any changes to server.xml or web.xml and works (at the very least) for me on Struts v1.0 v1.1 with Hibernate v2.0.3 V2.1beta6 under Tomcat 4.1.24 through 4.1.29. * Use a hibernate.cfg.xml file like so (passwords changed and pardon my MySQL slant) ?xml version='1.0' encoding='utf-8'? !DOCTYPE hibernate-configuration PUBLIC -//Hibernate/Hibernate Configuration DTD 2.0//EN http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd; hibernate-configuration session-factory name=dgf:/hibernate/SessionFactory property name=dialectnet.sf.hibernate.dialect.MySQLDialect/property property name=connection.usernameAA/property property name=connection.passwordBB/property property name=connection.urljdbc:mysql://localhost:3306/authors/property property name=connection.driver_classcom.mysql.jdbc.Driver/property property name=show_sqltrue/property property name=use_outer_jointrue/property property name=transaction.factory_classnet.sf.hibernate.transaction.JDBCTransactio nFactory/property property name=dbcp.minIdle1/property !-- Optional, I use this but it requires an opensymphony.org download of OSCache property name=cache.use_query_cachetrue/property property name=cache.provider_classnet.sf.hibernate.cache.OSCacheProvider/property -- !-- insert any mapping file so you don't need to hardcode adding classes or adding files in a Java class -- mapping resource=hibernate/Misc.hbm.xml/ /session-factory /hibernate-configuration The JNDI location is set in the session-factory tag using the 'name=' attribute. Whatever name you choose, DO NOT use anything starting java:comp/env as that is read-only in Tomcat and will NOT work. I made up a context named dgf:/hibernate/SessionFactory and was pleasantly surprised when hibernate created the context for me and stored the SessionFactory within it so I could us it in JNDI context lookups after I got the InitialContext and performed a ' SessionFactory sf = (SessionFactory) context.lookup(dgf:/hibernate/SessionFactory);'. I see you want to use DBCP. As long as you set a minimum of 1 dbcp property, hibernate will detect you want to use DBCP as your connection pool. Feel free to set more than one DBCP property or even to use something other than dbcp.minIdle as in my working example above. Hibernate can work with other connection pools. I recommend avoiding C3P0 as it can't shutdown (eats up memory unless you fully shutdown the JVM [i.e. TOMCAT] and restart). A Beta C3P0 allows shutdown of a C3P0 pool, but the last time I checked, the Hibernate controlling class for C3P0 pooling still had an empty finalize() and never actually shutdown my C3P0 pool. Regards, David -Original Message- From: David Erickson [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 16, 2003 7:20 PM To: Struts Mailing List Subject: Plea for help w/Struts-Hibernate Plugin that has it working! For some reason I just cannot make the Struts-Hibernate plugin work.. I can't make the Struts-Hibernate Listener work either. Here is the link to class I am trying to use: http://www.hibernate.org/133.html Here is the error I get without fail every time.. now note that this jndi connection WORKS fine when I use the HibernateUtil class, or when I use my own JDNI tests. Error: 2003-12-16 17:10:31,452 [DEBUG] impl.SessionImpl - opened session 2003-12-16 17:10:31,468 [DEBUG] transaction.JDBCTransaction - begin 2003-12-16 17:10:31,484 [DEBUG] util.JDBCExceptionReporter - SQL Exception java.sql.SQLException: Cannot load JDBC driver class 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.jav a:529) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:3 12) at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(Datas ourceConnectionProvider.java:59) at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:262) at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3155) at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3138) at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40) My setup: tomcat_home\common\lib contains: commons-dbcp.jar commons-pool.jar jdbc2_0-stdext.jar jndi.jar mysql-connector-java-3.0.8-stable-bin.jar hibernate2.jar etc Server.xml: DefaultContext Resource name=jdbc/Salesweb auth=Container type=javax.sql.DataSource/ ResourceParams name=jdbc/Salesweb parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter parameter namemaxActive/name value100/value /parameter parameter namemaxIdle/name value30/value /parameter