Announcement Announcement Module
Collapse
No announcement yet.
Connecting to Oracle Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connecting to Oracle

    I have a problem with connecting to a local oracle database. I am successfully connecting to it with Toad.

    I have the following database properties:

    Code:
    database.password=spentitroo
    database.url=jdbc\:oracle\:thin\:@localhost\:1521\:orcl
    database.username=spentitroo
    database.driverClassName=oracle.jdbc.OracleDriver
    If I use the Hypersonic_in_memory database, it all works fine.

  • #2
    Post the exception.

    Why do you have the / in the url, those shouldn't be there.

    Comment


    • #3
      Thanks. The reasons why i have the backslash is because they are there initially when you change the db to oracle. I've tried removing them, changed to this:

      Code:
      database.url=jdbc:oracle:thin:@localhost:1521:orcl
      But to no avail.

      Here is the error message for one of the Test. I tried running it with this code now (removing most of it thought, since its too big).

      Code:
      -------------------------------------------------------------------------------
      Test set: com.axehigh.spentitroo.domain.AccountIntegrationTest
      -------------------------------------------------------------------------------
      Tests run: 9, Failures: 0, Errors: 8, Skipped: 0, Time elapsed: 0.141 sec <<< FAILURE!
      testCountAccounts(com.axehigh.spentitroo.domain.AccountIntegrationTest)  Time elapsed: 0 sec  <<< ERROR!
      org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      	at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:382)
      	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:336)
      	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:293)
      	at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$before$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(AbstractTransactionAspect.aj:63)
      	at com.axehigh.spentitroo.domain.AccountDataOnDemand_Roo_DataOnDemand.ajc$interMethod$com_axehigh_spentitroo_domain_AccountDataOnDemand_Roo_DataOnDemand$com_axehigh_spentitroo_domain_AccountDataOnDemand$init(AccountDataOnDemand_Roo_DataOnDemand.aj:38)
      	at com.axehigh.spentitroo.domain.AccountDataOnDemand.init(AccountDataOnDemand.java:1)
      	at com.axehigh.spentitroo.domain.AccountDataOnDemand_Roo_DataOnDemand.ajc$interMethodDispatch1$com_axehigh_spentitroo_domain_AccountDataOnDemand_Roo_DataOnDemand$com_axehigh_spentitroo_domain_AccountDataOnDemand$init(AccountDataOnDemand_Roo_DataOnDemand.aj)
      	at com.axehigh.spentitroo.domain.AccountDataOnDemand_Roo_DataOnDemand.ajc$interMethod$com_axehigh_spentitroo_domain_AccountDataOnDemand_Roo_DataOnDemand$com_axehigh_spentitroo_domain_AccountDataOnDemand$getRandomAccount(AccountDataOnDemand_Roo_DataOnDemand.aj:27)
      	at com.axehigh.spentitroo.domain.AccountDataOnDemand.getRandomAccount(AccountDataOnDemand.java:1)
      	at com.axehigh.spentitroo.domain.AccountDataOnDemand_Roo_DataOnDemand.ajc$interMethodDispatch1$com_axehigh_spentitroo_domain_AccountDataOnDemand_Roo_DataOnDemand$com_axehigh_spentitroo_domain_AccountDataOnDemand$getRandomAccount(AccountDataOnDemand_Roo_DataOnDemand.aj)
      	at com.axehigh.spentitroo.domain.AccountIntegrationTest_Roo_IntegrationTest.ajc$interMethod$com_axehigh_spentitroo_domain_AccountIntegrationTest_Roo_IntegrationTest$com_axehigh_spentitroo_domain_AccountIntegrationTest$testCountAccounts(AccountIntegrationTest_Roo_IntegrationTest.aj:22)
      	at com.axehigh.spentitroo.domain.AccountIntegrationTest.testCountAccounts(AccountIntegrationTest.java:1)
      	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:597)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
      	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
      	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
      	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
      	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
      	at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
      	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:597)
      	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
      	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
      	at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:41)
      	at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
      	at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:332)
      	... 44 more

      Comment


      • #4
        Well you left out the interesting part ... Paste the stacktrace into a txt file and attach it here.

        The fact that you can connect with toad indicates only that your database is up. It doesn't say anything about the url or the fact that you have the drivers in your classpath.

        Comment


        • #5
          I think the drivers can be a good point. But I would think ROO together with maven would fix that for me - no ?

          Comment


          • #6
            Here is the test that has the full stack trace.

            Comment


            • #7
              @olona,

              Yes, the problem is that your application has no access to the Oracle JDBC driver: ClassNotFoundException: oracle.jdbc.driver.OracleDriver Roo can only supply dependencies which are available in public maven repositories such as Maven central and the SpringSource Enterprise Bundle Repository.

              The Oracle driver is a commercial driver and therefore not available in Maven repositories but you should have access to as part of your Oracle Database distribution. Therefore you will need to add this dependency yourself to your application (either to your project directly or as a dependency in your local Maven repo).

              HTH

              Comment


              • #8
                Alright!! So, I added the Oracle driver to the Maven repository, then added it manually to the POM, then changed

                database.driverClassName=oracle.jdbc.OracleDriver
                to
                database.driverClassName=oracle.jdbc.driver.Oracle Driver

                and it worked - finally :-)

                Comment


                • #9
                  Thanks for the feedback! Which driver version are you using? It appears Oracle has changed package structures... I can change this so at least we point to the correct driver class.

                  Comment


                  • #10
                    I am using the ojdbc14.jar, version 10.2.0. I added this to the pom.xml.

                    Code:
                    <dependency>
                    	<groupId>com.oracle</groupId>
                    	<artifactId>ojdbc14</artifactId>
                    	<version>10.2.0</version>
                    </dependency>

                    Comment


                    • #11
                      Originally posted by olona View Post
                      Alright!! So, I added the Oracle driver to the Maven repository, then added it manually to the POM, then changed

                      database.driverClassName=oracle.jdbc.OracleDriver
                      to
                      database.driverClassName=oracle.jdbc.driver.Oracle Driver

                      and it worked - finally :-)
                      Hmm, the oracle.jdbc.OracleDriver should actually have worked for you.

                      According to this Roo installs the correct driver:

                      For Oracle 8.x and previous releases, the package that contained the Oracle Thin driver was oracle.jdbc.driver. When configuring a JDBC connection pool that uses the Oracle 8.1.7 Thin driver, you specify the DriverName (Driver Classname) as oracle.jdbc.driver.OracleDriver. For Oracle 9.x and 10g, the package that contains the Oracle Thin driver is oracle.jdbc. When configuring a JDBC connection pool that uses the Oracle 9.x or 10g Thin driver, you specify the DriverName (Driver Classname) as oracle.jdbc.OracleDriver. You can use the oracle.jdbc.driver.OracleDriver class with the 9.x and 10g drivers, but Oracle may not make future feature enhancements to that class.
                      I just wanted to makes sure we do the right thing here. Can you confirm this?

                      Comment


                      • #12
                        I tried creating application with MYSQL

                        i typed following for doing so,

                        persistence setup --provider HIBERNATE --database MYSQL --databaseName trial_app userName root password mysql

                        i started the jetty server too successfully..

                        but when i m trying to make a new instance of the field in the class from the browser it gives me following error

                        Data access failure

                        Sorry, a problem occurred while accessing the database.

                        Details
                        -Exception Message
                        org.hibernate.exception.SQLGrammarException: could not insert: [org.trial_app.Trial]; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [org.trial_app.Trial]


                        Exception stackTrace...



                        -Exception Stack Trace
                        org.springframework.orm.jpa.EntityManagerFactoryUt ils.convertJpaAccessExceptionIfPossible(EntityMana gerFactoryUtils.java:312)
                        org.springframework.orm.jpa.aspectj.JpaExceptionTr anslatorAspect.ajc$afterThrowing$org_springframewo rk_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$ 18a1ac9(JpaExceptionTranslatorAspect.aj:15)
                        org.trial_app.Trial_Roo_Entity.ajc$interMethod$org _trial_app_Trial_Roo_Entity$org_trial_app_Trial$pe rsist(Trial_Roo_Entity.aj:49)
                        org.trial_app.Trial.persist(Trial.java:1)
                        org.trial_app.Trial_Roo_Entity.ajc$interMethodDisp atch1$org_trial_app_Trial_Roo_Entity$org_trial_app _Trial$persist(Trial_Roo_Entity.aj)
                        org.trial_app.TrialController_Roo_Controller.ajc$i nterMethod$org_trial_app_TrialController_Roo_Contr oller$org_trial_app_TrialController$create(TrialCo ntroller_Roo_Controller.aj:23)
                        org.trial_app.TrialController.create(TrialControll er.java:1)
                        sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
                        sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
                        sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
                        java.lang.reflect.Method.invoke(Method.java:597)
                        org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.doInvokeMethod(HandlerMethodInv oker.java:710)
                        org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth odInvoker.java:167)
                        org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:414)
                        org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:402)
                        org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:771)
                        org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:716)
                        org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:647)
                        org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:563)
                        javax.servlet.http.HttpServlet.service(HttpServlet .java:727)
                        javax.servlet.http.HttpServlet.service(HttpServlet .java:820)
                        org.mortbay.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:487)
                        org.mortbay.jetty.servlet.ServletHandler.handle(Se rvletHandler.java:362)
                        org.mortbay.jetty.security.SecurityHandler.handle( SecurityHandler.java:216)
                        org.mortbay.jetty.servlet.SessionHandler.handle(Se ssionHandler.java:181)
                        org.mortbay.jetty.handler.ContextHandler.handle(Co ntextHandler.java:726)
                        org.mortbay.jetty.webapp.WebAppContext.handle(WebA ppContext.java:405)
                        org.mortbay.jetty.servlet.Dispatcher.forward(Dispa tcher.java:285)
                        org.mortbay.jetty.servlet.Dispatcher.forward(Dispa tcher.java:126)
                        org.tuckey.web.filters.urlrewrite.NormalRewrittenU rl.doRewrite(NormalRewrittenUrl.java:195)
                        org.tuckey.web.filters.urlrewrite.RuleChain.handle Rewrite(RuleChain.java:159)
                        org.tuckey.web.filters.urlrewrite.RuleChain.doRule s(RuleChain.java:141)
                        org.tuckey.web.filters.urlrewrite.UrlRewriter.proc essRequest(UrlRewriter.java:90)
                        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter .doFilter(UrlRewriteFilter.java:417)
                        org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1084)
                        org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal(HiddenHttpMethodFilter.java:7 1)
                        org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
                        org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1084)
                        org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :88)
                        org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
                        org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1084)
                        org.springframework.web.filter.ShallowEtagHeaderFi lter.doFilterInternal(ShallowEtagHeaderFilter.java :57)
                        org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
                        org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1084)
                        org.springframework.orm.jpa.support.OpenEntityMana gerInViewFilter.doFilterInternal(OpenEntityManager InViewFilter.java:113)
                        org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
                        org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1084)
                        org.mortbay.jetty.servlet.ServletHandler.handle(Se rvletHandler.java:360)
                        org.mortbay.jetty.security.SecurityHandler.handle( SecurityHandler.java:216)
                        org.mortbay.jetty.servlet.SessionHandler.handle(Se ssionHandler.java:181)
                        org.mortbay.jetty.handler.ContextHandler.handle(Co ntextHandler.java:726)
                        org.mortbay.jetty.webapp.WebAppContext.handle(WebA ppContext.java:405)
                        org.mortbay.jetty.handler.ContextHandlerCollection .handle(ContextHandlerCollection.java:206)
                        org.mortbay.jetty.handler.HandlerCollection.handle (HandlerCollection.java:114)
                        org.mortbay.jetty.handler.HandlerWrapper.handle(Ha ndlerWrapper.java:152)
                        org.mortbay.jetty.Server.handle(Server.java:324)
                        org.mortbay.jetty.HttpConnection.handleRequest(Htt pConnection.java:505)
                        org.mortbay.jetty.HttpConnection$RequestHandler.co ntent(HttpConnection.java:843)
                        org.mortbay.jetty.HttpParser.parseNext(HttpParser. java:648)
                        org.mortbay.jetty.HttpParser.parseAvailable(HttpPa rser.java:211)
                        org.mortbay.jetty.HttpConnection.handle(HttpConnec tion.java:380)
                        org.mortbay.io.nio.SelectChannelEndPoint.run(Selec tChannelEndPoint.java:395)
                        org.mortbay.thread.QueuedThreadPool$PoolThread.run (QueuedThreadPool.java:488)



                        Please help me resolve this error..

                        Thanks..
                        Sweta

                        Comment


                        • #13
                          Sweta,

                          First, please create a new thread for your problem since this is unrelated to the Oracle configuration issue this thread is about.

                          Second, it would be great if you could share your complete script in the new thread along with this stack trace so we can see what you are doing. Maybe you are using a reserved word as field name?

                          Comment


                          • #14
                            Also please include your src/main/resources/META-INF/spring/database.properties file in the post.

                            Comment


                            • #15
                              Originally posted by Stefan Schmidt View Post
                              Hmm, the oracle.jdbc.OracleDriver should actually have worked for you.

                              According to this Roo installs the correct driver:

                              I just wanted to makes sure we do the right thing here. Can you confirm this?
                              Hey Stefan, sorry for the delay.

                              It seems you're right. What I did was downloading the oracle jdbc driver for the Oracle database I am using (10g 10.2.0.1.0) and installed this into the repository, and it seems there is no difference wether using oracle.jdbc.OracleDriver or oracle.jdbc.driver.OracleDriver.

                              If I put in anything else, it will fail however.

                              Comment

                              Working...
                              X