- This topic has 5 replies, 4 voices, and was last updated 14 years, 6 months ago by support-shalini.
-
AuthorPosts
-
Waldo RochowMemberI am trying to create a stand-alone db-aware java app using Hibernate to access a mySQL database hosted on my ISP’s server.
I am able to browse the database using the DBExplorer in myEclipse. I use the myEclipse wizards to generate my hibernate configuration…
<?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> <property name="myeclipse.connection.profile">BCBC</property> <property name="connection.url">jdbc:mysql://domain.com:3306/domain_bcbc</property> <property name="connection.username">username</property> <property name="connection.password">password</property> <property name="connection.driver_class">com.mysql.jdbc.NonRegisteringDriver</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <mapping resource="com/domain/hibernate/User.hbm.xml" /> </session-factory> </hibernate-configuration>
The wizards (“Add Hibernate Capabilities…” & “Create Hibernate Mapping”) don’t complain at all.
My DAO method is…
public static final User getE107User(int id){ User user = new User(); Session session = null; try { session = HibernateSessionFactory.currentSession(); } catch (HibernateException e) { e.printStackTrace(); } try { Transaction tx = session.beginTransaction(); user = (User)session.get(User.class, new Integer(id)); System.out.println("User #"+id+" is: "+ user.getName()); tx.commit(); } catch (HibernateException e) { e.printStackTrace(); } finally { session.close(); } return user; }
When stepping through it with the debugger, if fails in “Transaction tx = session.beginTransaction();” with the following output to the console:
org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92) at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110) at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:137) at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:49) at org.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:24) at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:271) at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1079) at com.domain.dao.UserDAO.getUser(UserDAO.java:23) at com.domain.dao.UserDAOTest.testGetUser(UserDAOTest.java:14) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection(DriverManager.java:545) at java.sql.DriverManager.getConnection(DriverManager.java:140) at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:298) ... 23 more
I am working with:
- + Eclipse SDK
Version: 3.1.1
Build id: M20050929-0840- + MyEclipse JSF Support
Version: 4.0.1
Build id: 20050930-4.0.1-GA- + jdk1.5.0_04
We use hibernate at work in a J2EE environment, but I was of the understanding that with Hibernate you don’t need to be in a container to make it work.
I find it odd that the myEclipse DBExplorer is able to connect to and query the database, however code that is generated by it cannot.
I’ve scoured this forum, and haven’t seen this discussed yet.
Any advice you can offer would be greatly appreciated…PS: Yes, the mysql jar is in the classpath… ;o)
Brian FernandesModeratorwrochow,
Just a quick suggestion: could you change
<property name=”connection.driver_class”>com.mysql.jdbc.NonRegisteringDriver</property>
to
<property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>
in your hibernate configuration file and see if that works for you?
Best,
Brian.
Waldo RochowMemberWoo Hoo!!
That’s exactly the problem!
Thank you for your prompt reply… I should have posted this question days ago!
</PAIN>
Brian FernandesModeratorGlad to be of assistance 🙂
Brian.
andresaunMemberHello,
I have an error “Cannot open connection” when I try to connect database Oracle from NetBeans using hibernate.
The web application worked find until I had reinstalled Oracle. For this reason I think that I have to do some configuration in Oracle to able the connection with hibernate.
Please, help me with this problem.
Thanks
ANDRES S.
support-shaliniMemberAndres,
from NetBeans using hibernate.
Are you using NetBeans IDE? Please cross post to Netbeans forums.
-
AuthorPosts