Announcement Announcement Module
Collapse
No announcement yet.
Integration Spring3.2.2 with Hibernate4.1 Error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Integration Spring3.2.2 with Hibernate4.1 Error

    Hello ,
    I use hibernate 4.1 and spring 3.2.2
    i've this exception


    Exception in thread "main" org.springframework.transaction.CannotCreateTransa ctionException: Could not open Hibernate Session for transaction; nested exception is java.lang.UnsupportedOperationException: Not supported by BasicDataSource
    at org.springframework.orm.hibernate4.HibernateTransa ctionManager.doBegin(HibernateTransactionManager.j ava:514)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.getTransaction(AbstractPl atformTransactionManager.java:372)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.createTransactionIfNecessary(Tr ansactionAspectSupport.java:417)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.invokeWithinTransaction(Transac tionAspectSupport.java:255)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:94)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy13.sayHello(Unknown Source)
    at test.com.gpao.service.Main.main(Main.java:27)
    Caused by: java.lang.UnsupportedOperationException: Not supported by BasicDataSource
    at org.apache.commons.dbcp.BasicDataSource.getConnect ion(BasicDataSource.java:1062)
    at org.hibernate.service.jdbc.connections.internal.Da tasourceConnectionProviderImpl.getConnection(Datas ourceConnectionProviderImpl.java:141)
    at org.hibernate.internal.AbstractSessionImpl$NonCont extualJdbcConnectionAccess.obtainConnection(Abstra ctSessionImpl.java:292)
    at org.hibernate.engine.jdbc.internal.LogicalConnecti onImpl.obtainConnection(LogicalConnectionImpl.java :297)
    at org.hibernate.engine.jdbc.internal.LogicalConnecti onImpl.getConnection(LogicalConnectionImpl.java:16 9)
    at org.hibernate.engine.transaction.internal.jdbc.Jdb cTransaction.doBegin(JdbcTransaction.java:67)
    at org.hibernate.engine.transaction.spi.AbstractTrans actionImpl.begin(AbstractTransactionImpl.java:160)
    at org.hibernate.internal.SessionImpl.beginTransactio n(SessionImpl.java:1395)
    at org.springframework.orm.hibernate4.HibernateTransa ctionManager.doBegin(HibernateTransactionManager.j ava:473)
    ... 8 more




    my beans.xml is

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.2.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-3.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/btest"/>
    <property name="username" value="root"/>
    <property name="password" value=""/>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSes sionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan" value="com.myapplication.entity" />
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.transaction.factory_class">org.hibe rnate.transaction.JDBCTransactionFactory</prop>
    </props>
    </property>
    </bean>


    <bean id="transactionManager" class="org.springframework.orm.hibernate4.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <context:annotation-config />
    <context:component-scan base-package="com.myapplication"/>

    </beans>

    Can any one help me please ???

  • #2
    Hello

    1) use code tags
    2) remove
    Code:
    <prop key="hibernate.transaction.factory_class">org.hibe rnate.transaction.JDBCTransactionFactory</prop>

    Try it...let me know your advance

    Comment


    • #3
      thanks for reply
      i'm removed this property !! but i have the same exception

      Comment


      • #4
        Ok

        UnsupportedOperationException: Not supported by BasicDataSource
        Change BasicDataSource to C3PO...

        BasicDataSource should not be used for production

        Comment


        • #5
          i'm changed the BasicDataSource to C3P0 ! but now i've other exception

          Exception in thread "main" org.springframework.transaction.CannotCreateTransa ctionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.SQLGrammarException: Could not open connection
          at org.springframework.orm.hibernate4.HibernateTransa ctionManager.doBegin(HibernateTransactionManager.j ava:514)
          at org.springframework.transaction.support.AbstractPl atformTransactionManager.getTransaction(AbstractPl atformTransactionManager.java:372)
          at org.springframework.transaction.interceptor.Transa ctionAspectSupport.createTransactionIfNecessary(Tr ansactionAspectSupport.java:417)
          at org.springframework.transaction.interceptor.Transa ctionAspectSupport.invokeWithinTransaction(Transac tionAspectSupport.java:255)
          at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:94)
          at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
          at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
          at com.sun.proxy.$Proxy13.sayHello(Unknown Source)
          at test.com.gpao.service.Main.main(Main.java:35)
          Caused by: org.hibernate.exception.SQLGrammarException: Could not open connection
          at org.hibernate.exception.internal.SQLExceptionTypeD elegate.convert(SQLExceptionTypeDelegate.java:82)
          at org.hibernate.exception.internal.StandardSQLExcept ionConverter.convert(StandardSQLExceptionConverter .java:49)
          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.c onvert(SqlExceptionHelper.java:125)
          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.c onvert(SqlExceptionHelper.java:110)
          at org.hibernate.engine.jdbc.internal.LogicalConnecti onImpl.obtainConnection(LogicalConnectionImpl.java :304)
          at org.hibernate.engine.jdbc.internal.LogicalConnecti onImpl.getConnection(LogicalConnectionImpl.java:16 9)
          at org.hibernate.engine.transaction.internal.jdbc.Jdb cTransaction.doBegin(JdbcTransaction.java:67)
          at org.hibernate.engine.transaction.spi.AbstractTrans actionImpl.begin(AbstractTransactionImpl.java:160)
          at org.hibernate.internal.SessionImpl.beginTransactio n(SessionImpl.java:1395)
          at org.springframework.orm.hibernate4.HibernateTransa ctionManager.doBegin(HibernateTransactionManager.j ava:473)
          ... 8 more
          Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Accesss refused for user: ''@'@localhost'. Base 'btest'
          at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
          at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
          at java.lang.reflect.Constructor.newInstance(Unknown Source)
          at com.mysql.jdbc.Util.handleNewInstance(Util.java:41 1)
          at com.mysql.jdbc.Util.getInstance(Util.java:386)
          at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1054)
          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:4120)
          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:4052)
          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:925)
          at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggab leAuthentication(MysqlIO.java:1704)
          at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:12 50)
          at com.mysql.jdbc.ConnectionImpl.coreConnect(Connecti onImpl.java:2483)
          at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(Co nnectionImpl.java:2516)
          at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2301)
          at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImp l.java:834)
          at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connect ion.java:47)
          at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
          at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
          at java.lang.reflect.Constructor.newInstance(Unknown Source)
          at com.mysql.jdbc.Util.handleNewInstance(Util.java:41 1)
          at com.mysql.jdbc.ConnectionImpl.getInstance(Connecti onImpl.java:416)
          at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:317)
          at com.mchange.v2.c3p0.DriverManagerDataSource.getCon nection(DriverManagerDataSource.java:135)
          at com.mchange.v2.c3p0.WrapperConnectionPoolDataSourc e.getPooledConnection(WrapperConnectionPoolDataSou rce.java:182)
          at com.mchange.v2.c3p0.WrapperConnectionPoolDataSourc e.getPooledConnection(WrapperConnectionPoolDataSou rce.java:171)
          at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolM anager.ensureFirstConnectionAcquisition(C3P0Pooled ConnectionPoolManager.java:845)
          at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolM anager.createPooledConnectionPool(C3P0PooledConnec tionPoolManager.java:733)
          at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolM anager.getPool(C3P0PooledConnectionPoolManager.jav a:257)
          at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolM anager.getPool(C3P0PooledConnectionPoolManager.jav a:249)
          at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSou rce.getConnection(AbstractPoolBackedDataSource.jav a:134)
          at org.hibernate.service.jdbc.connections.internal.Da tasourceConnectionProviderImpl.getConnection(Datas ourceConnectionProviderImpl.java:141)
          at org.hibernate.internal.AbstractSessionImpl$NonCont extualJdbcConnectionAccess.obtainConnection(Abstra ctSessionImpl.java:292)
          at org.hibernate.engine.jdbc.internal.LogicalConnecti onImpl.obtainConnection(LogicalConnectionImpl.java :297)


          Please note that all database informations are correct (url, username, password, driverClass)

          Comment


          • #6
            When you write a post...above you can see the icon #, use that for code tags

            Code:
            Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
            Accesss refused for user: ''@'@localhost'. Base 'btest'
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            You cant connect to your DB...be sure you have the correct URL and required password...

            Comment


            • #7
              yes , i'm sure , this is the correct url, user, and password

              Comment


              • #8
                I dont think so

                Code:
                <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost/btest"/>
                <property name="username" value="root"/>
                <property name="password" value=""/>
                Where is the port number in the URL? ....and the password is empty....

                Comment


                • #9
                  @dr_pompei : thank you for all responses !! i'm placed all hibernate properties on the file hibernate.properties and it work now

                  Comment

                  Working...
                  X