These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Help Newbie: org.hibernate.exception.GenericJDBCException
PostPosted: Wed May 31, 2006 3:20 am 
Newbie

Joined: Wed May 31, 2006 3:03 am
Posts: 9
Hibernate version: 3

Mapping documents:contact.hbm.xml,hibernate.cfg.xml

Here is where I am configuring connection settings in hibernate.cfg.xml

Code:
   <session-factory>
      <property name="hibernate.connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>
      <property name="hibernate.connection.url">jdbc:odbc:cs</property>
      <property name="hibernate.connection.username">abc_14</property>
      <property name="hibernate.connection.password">abc_14</property>


Code between sessionFactory.openSession() and session.close():

Code:
System.out.println("Inserting Record");
   Contact contact = new Contact();
   contact.setId(6);
   contact.setFirstName("Fee");
   contact.setLastName("Lee");
   contact.setEmail("feelee@yoo.com");
   session.save(contact);
   System.out.println("Done");
   }catch(Exception e){
      System.out.println(e.getMessage());
   }finally{
   // Actual contact insertion will happen at this step
         session.flush();


Full stack trace of any exception that occurs:

Code:
Exception in thread "main" 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.AbstractBatcher.openConnection(AbstractBatcher.java:384)
   at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
   at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:73)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:66)
   at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:130)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1809)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
   at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:31)
Caused by: java.sql.SQLException: [Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve service name
   at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
   at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:381)
   ... 15 more



Name and version of the database you are using: Oracle 8i

Debug level Hibernate log excerpt:

Code:
11:26:37,171  INFO Environment:456 - Hibernate 3.0rc1
11:26:37,171  INFO Environment:469 - hibernate.properties not found
11:26:37,187  INFO Environment:502 - using CGLIB reflection optimizer
11:26:37,187  INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
11:26:37,187  INFO Configuration:1228 - configuring from resource: /hibernate.cfg.xml
11:26:37,187  INFO Configuration:1199 - Configuration resource: /hibernate.cfg.xml
11:26:37,546  INFO Configuration:439 - Mapping resource: contact.hbm.xml
11:26:37,703  INFO HbmBinder:256 - Mapping class: roseindia.tutorial.hibernate.Contact -> CONTACT
11:26:37,734  INFO HbmBinder:256 - Mapping class: roseindia.tutorial.hibernate.Book -> book
11:26:37,734  INFO HbmBinder:256 - Mapping class: roseindia.tutorial.hibernate.Insurance -> insurance
11:26:37,734  INFO Configuration:1340 - Configured SessionFactory: null
11:26:37,734  INFO Configuration:844 - processing extends queue
11:26:37,734  INFO Configuration:848 - processing collection mappings
11:26:37,734  INFO Configuration:857 - processing association property references
11:26:37,734  INFO Configuration:884 - processing foreign key constraints
11:26:37,828  INFO Dialect:89 - Using dialect: org.hibernate.dialect.OracleDialect
11:26:37,843  INFO SettingsFactory:90 - Default batch fetch size: 1
11:26:37,843  INFO SettingsFactory:94 - Generate SQL with comments: disabled
11:26:37,843  INFO SettingsFactory:98 - Order SQL updates by primary key: disabled
11:26:37,843  INFO SettingsFactory:273 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
11:26:37,859  INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
11:26:37,859  INFO SettingsFactory:106 - Query language substitutions: {}
11:26:37,859  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
11:26:37,875  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
11:26:37,875  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
11:26:37,875  INFO DriverManagerConnectionProvider:80 - using driver: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:cs
11:26:37,875  INFO DriverManagerConnectionProvider:86 - connection properties: {user=abc_14, password=****}
11:26:38,140  WARN SettingsFactory:142 - Could not obtain connection metadata
java.sql.SQLException: [Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve service name
   at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:118)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1497)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1041)
   at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:16)
11:26:38,140  INFO SettingsFactory:148 - JDBC batch size: 15
11:26:38,140  INFO SettingsFactory:151 - JDBC batch updates for versioned data: disabled
11:26:38,140  INFO SettingsFactory:156 - Scrollable result sets: disabled
11:26:38,140  INFO SettingsFactory:164 - JDBC3 getGeneratedKeys(): disabled
11:26:38,140  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
11:26:38,156  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
11:26:38,156  INFO SettingsFactory:176 - Automatic flush during beforeCompletion(): disabled
11:26:38,156  INFO SettingsFactory:179 - Automatic session close at end of transaction: disabled
11:26:38,156  INFO SettingsFactory:260 - Cache provider: org.hibernate.cache.EhCacheProvider
11:26:38,156  INFO SettingsFactory:187 - Second-level cache: enabled
11:26:38,156  INFO SettingsFactory:192 - Optimize cache for minimal puts: disabled
11:26:38,156  INFO SettingsFactory:199 - Structured second-level cache entries: enabled
11:26:38,156  INFO SettingsFactory:203 - Query cache: disabled
11:26:38,156  INFO SettingsFactory:210 - Echoing all SQL to stdout
11:26:38,156  INFO SettingsFactory:214 - Statistics: disabled
11:26:38,156  INFO SettingsFactory:218 - Deleted entity synthetic identifier rollback: disabled
11:26:38,171  INFO SettingsFactory:232 - Default entity-mode: pojo
11:26:38,359  INFO SessionFactoryImpl:140 - building session factory
11:26:38,359 DEBUG CacheManager:191 - Creating new CacheManager with default config
11:26:38,359 DEBUG CacheManager:164 - Configuring ehcache from classpath.
11:26:38,375  WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/hibernate/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
11:26:38,390 DEBUG Configuration$DiskStore:185 - Disk Store Path: C:\DOCUME~1\alim\LOCALS~1\Temp\
11:26:38,812  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
11:26:38,812  INFO Dialect:89 - Using dialect: org.hibernate.dialect.OracleDialect
11:26:38,812  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
11:26:38,812  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
11:26:38,812  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
11:26:38,828  INFO DriverManagerConnectionProvider:80 - using driver: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:cs
11:26:38,828  INFO DriverManagerConnectionProvider:86 - connection properties: {user=abc_14, password=****}
11:26:38,828  INFO SchemaUpdate:105 - Running hbm2ddl schema update
11:26:38,828  INFO SchemaUpdate:117 - fetching database metadata
11:26:38,828 ERROR SchemaUpdate:129 - could not get database metadata
java.sql.SQLException: [Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve service name
   at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
   at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:118)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:252)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
   at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:16)
11:26:38,828 ERROR SchemaUpdate:158 - could not complete schema update
java.sql.SQLException: [Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve service name
   at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
   at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:118)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:252)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
   at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:16)
11:26:38,843  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:odbc:cs
11:26:38,843  INFO SessionFactoryImpl:366 - Checking 0 named queries
11:26:38,843  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:odbc:cs
Inserting Record
Done
11:26:38,921  WARN JDBCExceptionReporter:57 - SQL Error: 12154, SQLState: 08004
11:26:38,921 ERROR JDBCExceptionReporter:58 - [Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve service name
11:26:38,921 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
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.AbstractBatcher.openConnection(AbstractBatcher.java:384)
   at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
   at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:73)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:66)
   at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:130)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1809)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
   at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:31)
Caused by: java.sql.SQLException: [Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve service name
   at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at java.sql.DriverManager.getConnection(Unknown Source)
   at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
   at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:381)
   ... 15 more


Last edited by WarriorPrincess on Wed May 31, 2006 3:33 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 3:24 am 
Newbie

Joined: Wed Dec 14, 2005 3:57 am
Posts: 3
[Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve service name


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 3:38 am 
Newbie

Joined: Wed May 31, 2006 3:03 am
Posts: 9
yashucn wrote:
[Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve service name


Thanks for the quick reply.

If you meant to point out that the service wasnt running; the service is running - I have checked it through a simple jsp..

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:cs", "abc_14", "abc_14");


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 3:48 am 
Newbie

Joined: Wed Dec 14, 2005 3:57 am
Posts: 3
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:cs</property>
<property name="hibernate.connection.username">abc_14</property>
<property name="hibernate.connection.password">abc_14</property>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 4:01 am 
Newbie

Joined: Wed May 31, 2006 3:03 am
Posts: 9
yashucn wrote:
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
</property>


= Result =

FATAL DriverManagerConnectionProvider:65 - JDBC Driver class not found: oracle.jdbc.driver.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 4:28 am 
Newbie

Joined: Wed Dec 14, 2005 3:57 am
Posts: 3
you should add "classes12.jar" on the build path.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 5:31 am 
Newbie

Joined: Wed May 31, 2006 3:03 am
Posts: 9
"classes12.jar" downloaded from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc817.htmland added "classes12.jar" to the build directory & path.

Code:
14:25:01,359  INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:odbc:1521:cs
14:25:01,359  INFO DriverManagerConnectionProvider:86 - connection properties: {user=abc_14, server_auth=yes>, password=****}
14:25:01,359  WARN SettingsFactory:142 - Could not obtain connection metadata java.sql.SQLException: No suitable driver Exception in thread "main"
14:25:02,171
ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Cannot open connection


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 7:27 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
This isn't a Hibernate issue.

You're using a different JDBC URL in your JSP test vs. your "Hibernate" application.

JSP:
Quote:
Connection con = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:cs", "abc_14", "abc_14");


Hibernate:
Quote:
jdbc:odbc:1521:cs


You are trying to use the Sun JDBC-ODBC driver in Hibernate (and it correctly is returning "no suitable driver"), while your JSP test is attempting to use the Oracle thin driver.

Either it's a simple typo, or you should probably read a bit about JDBC basics.

Hope that helps...[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 8:31 am 
Newbie

Joined: Wed May 31, 2006 3:03 am
Posts: 9
pmularien wrote:
You are trying to use the Sun JDBC-ODBC driver in Hibernate (and it correctly is returning "no suitable driver"), while your JSP test is attempting to use the Oracle thin driver.

Either it's a simple typo, or you should probably read a bit about JDBC basics.

Hope that helps...

arrrhhh.. Thanks for piontin out pmularien - unnecessary use of copy-paste i'd say!! Problem should have been over when ..
yashucn wrote:
you should add "classes12.jar" on the build path.

Thanks yashucn for your assistance - issue resolved!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.