Hello there,
I am having trouble in using Hibernate to connect to my database.
I am using tomcat 5.5.27, MySQL database Server and GWT.
My application-name.xml file (Context file) looks like the following: ---------------------------------------------------------------------------------------- <Context path="/testCase" docBase="${catalina.home}/webapps/testCase" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/MySQLDB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="user" password="passwd" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/testDB?autoReconnect=true" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" />
</Context> ----------------------------------------------------------------------------------------- My hibernate.cfg.xml looks like: ----------------------------------------------------------------------------------------- <hibernate-configuration> <session-factory> <property name="connection.datasource">java:comp/env/jdbc/MySQLDB</property> <!-- <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/testDB</property> <property name="connection.username">user</property> <property name="connection.password">passwd</property> --> <property name="connection.pool_size">1</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="current_session_context_class">thread</property> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup <property name="hbm2ddl.auto"></property> --> <mapping resource="com/duke/irb/client/data/User.hbm.xml"/> </session-factory> </hibernate-configuration> ------------------------------------------------------------------------------------- web.xml -------------------------------------------------------------------------------------- <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/MySQLDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> -------------------------------------------------------------------------------------- While I am trying to connect to my databse by code like: -------------------------------------------------------------------------------------- public class HibernateUtil { private static final SessionFactory sessionFactory;
static { try { sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { System.err.println("Hibernate Error:::::Initial SessionFactory creation failed." + ex); ex.printStackTrace(); ex.getCause(); ex.getLocalizedMessage(); ex.getMessage(); ex.getClass(); throw new ExceptionInInitializerError(ex); } }
public static SessionFactory getSessionFactory() { return sessionFactory; } ---------------------------------------------------------- session.beginTransaction(); result = session.createQuery("from User as u where u.user_id = :uid and u.passwd = :pass") .setString("uid", user) .setString("pass", pass) .list(); session.getTransaction().commit(); session.close(); ------------------------------------------------------------ It gives me the following exception: ------------------------------------------------------------------------ 359 [http-8080-1] INFO org.hibernate.impl.SessionFactoryImpl - building session factory 578 [http-8080-1] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured java.lang.UnsupportedOperationException: Not supported by BasicDataSource at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:899) at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:89) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353) at com.duke.irb.server.DBConnectionImpl.authenticateUser(DBConnectionImpl.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527) at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:166) at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:835) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286) at java.lang.Thread.run(Unknown Source) Error occured while trying to fetch users:::Not supported by BasicDataSource
------------------------------------------------------------------------------
I am not be able to connect ...
Kindly put some help....
Thanks in advance....
Raul
|