0

My application is using Spring 4, Hibernate 4, Java 1.7. This is a desktop application rather than a web application, so there is no server involved. I'm trying to create a connection to the database. For brevity's sake--I can't copy and paste--I left out some non-essential stuff to the problem. Here's my spring config:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="oracle.jdbc.OracleDriver" />
    <property name="jdbcUrl" value="jdbc:oracle:thin:@dbServer:1521:service" />
    <property name="properties">
        <props>
            <prop key="user">user</prop>
            <prop key="password">password</prop>
        </props>
    </property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.help.please" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.connection.autocommit">true</prop>
        </props>
    </property>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

I have the sessionFactory autowired into a DAO. When I try to obtain a connection from the sessionFactory, the logs look like so (again, shortened):

INFO [main] C3P0Registry:216 Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
INFO [main] Version:66 - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
INFO [main] Version:54 - HHH000412: Hibernate Core {4.3.8.Final}
INFO [main] Environment:224 - HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
INFO [main] Environment:346 - HHH000021: Bytecode provider name : javassist
INFO [main] AbstractPoolBackedDataSource:522 - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailer -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> [mumbo jumbo], debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> [mumbo jumbo], idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@dbServer:1521:service, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=****, password=********}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
WARN [main] JdbcServicesImpl:204 - HHH000342: Could not obtain connection to query metadata : ORA-01017: invalid username/password; logon denied

I am successfully able to use the user to login to the database using other applications as well as SQL Developer. I've made sure multiple times that the user/password is correct. I've tried using both ojdbc6.jar and ojdbc7.jar in hopes that it might be that. I've done some research and saw that it might be that the username/password might be automatically being capitalized before being sent to Oracle, but I know of know way of verifying that.

A note that might be important is that this code was connecting to the database just fine when I was using Spring 3 and Hibernate 3. Any suggestions as to how I can fix this problem?

EDIT

It's important to note that I'm using a combination of annotations and xml to configure my project. I'm using @Autowired to inject my services, daos, and session factory. I'm using @Transactional and @Repository in my dao layer. I don't know if that makes a difference or not, but please see my answer below to see how I got it working.

sfedak
  • 676
  • 6
  • 20
  • Look at this:http://stackoverflow.com/questions/28945312/ora-01017-when-connecting-through-jdbc-thin-driver – René Winkler Mar 13 '15 at 17:57
  • You are getting an ORA error, so you are connecting correctly to the database. The issue is with the username and/or password. You need to verify that what you put in the datasource properties is the correct username and password, and those are case sensitive. – LucasP Mar 13 '15 at 17:59
  • I tried to illustrate that I indeed did make sure--multiple times--that I used the same user/password for multiple applications as well as in SQL Developer. I'll edit my post to make that more explicit. – sfedak Mar 13 '15 at 18:15
  • @RenéWinkler has a link that looks like it could be related. I'm at a loss for what to do if you are sure the user/pass is correct and that link does not work for you. – LucasP Mar 13 '15 at 18:19
  • Yeah, I'm going to investigate that tomorrow and I'll let you guys know. Thanks! – sfedak Mar 13 '15 at 18:20
  • You already said you checked username and password, but just maybe it was case sensitive and in Oracle 11 username and password became case sensitieve. – avk Mar 13 '15 at 18:37
  • 1
    Why aren't you just setting the user and password properties directly on the `ComboPooledDataSource` instead of trying to put them in the additional JDBC `properties` property. – M. Deinum Mar 13 '15 at 18:45
  • @M.Deinum I did try that before, setting them in the additional JDBC `properties` property was just the current state of me trying to debug this thing. – sfedak Mar 16 '15 at 10:36
  • @RenéWinkler I tried the suggestion from that question and it didn't seem to do it. I'm still getting the same behavior. – sfedak Mar 16 '15 at 11:53
  • @avk, I had this working before using Spring 3, Hibernate 3, and Java 6. I was using ojdbc6.jar before and it was signing in. Do you think that any of these changes would make case sensitivity an issue in this case? – sfedak Mar 16 '15 at 11:54
  • @sfedak, no it shouldn't have. Still, can you login using sqlplus ? – avk Mar 16 '15 at 13:13
  • @avk yes, I can still login using sqlplus – sfedak Mar 16 '15 at 17:54

1 Answers1

1

I found that I needed to add a hibernate.cfg.xml file to my spring sessionFactory bean.

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.url">jdbc:oracle:thin:@dbServer:1521:service</property>
        <property name="connection.username">user</property>
        <property name="connection.password">password</property>
        <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="hibernate.connection.autocommit">true</property>
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="hibernate.show_sql">true</property>
    </session-factory>
</hibernate-configuration>

Now my spring configuration changed to look like so:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="oracle.jdbc.OracleDriver" />
    <property name="jdbcUrl" value="jdbc:oracle:thin:@dbServer:1521:service" />
    <property name="user" value="user" />
    <property name="password" value="password" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.help.please" />
    <property name="configLocation">
        <value>classpath:com.help.please/hibernate.cfg.xml</value>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

I'm not too sure of the explanation for why this works, but the way I think it was explained to me is that the properties weren't all getting passed to Hibernate, so configuring Hibernate like that and Spring like that helps it get the correct configuration that it needs. Please feel free to correct me if I'm wrong.

sfedak
  • 676
  • 6
  • 20