获取应用程序必须提供JDBC连接异常

时间:2016-07-22 05:47:56

标签: mysql spring hibernate jpa

我正在使用Spring + hibernate尝试在Mysql DB上执行查询时应用程序必须提供JDBC连接异常

应用程序上下文有以下条目

<bean id="jdbc" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="appDataSource" />      
</bean>

<bean id="appDataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="org.mariadb.jdbc.Driver" />
        <property name="url" value="jdbc:mariadb://localhost:3306/appdb" />
        <property name="username" value="username" />
        <property name="password" value="password" />
</bean>

JNDI名称为

<jee:jndi-lookup id="appDataSource" jndi-name="java:comp/env/jdbc/Modeling"/>

完成堆栈跟踪

    java.lang.UnsupportedOperationException: The application must supply JDBC connections
at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:44)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:386)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:84)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:    )
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:47)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1927)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1896)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1874)
at org.hibernate.loader.Loader.doQuery(Loader.java:919)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2610)
at org.hibernate.loader.Loader.doList(Loader.java:2593)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
at org.hibernate.loader.Loader.list(Loader.java:2417)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1339)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)
at org.hibernate.internal.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:964)

Hibernate配置

<hibernate-configuration>
    <session-factory>
        <mapping resource="service.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

Service.hbm.xml文件

<hibernate-mapping>
   <class name="service.repository.Account"
        table="ACCOUNTS" discriminator-value="null">
        <id name="id" column="id" type="java.lang.Long">
        //all other entry
   </class>
</hibernate-mapping>

3 个答案:

答案 0 :(得分:1)

执行以下操作 -

1)检查hibernate.cgf.xml(或你的hibernate配置文件)&amp;确认以下是否正确 -

hibernate.connection.url
hibernate.connection.username
hibernate.connection.password
hibernate.dialect
hibernate.connection.driver_class

2)检查您在standalone.xml(JBoss配置文件)中定义的数据源名称。它应该与您的jndi-name =&#34; java: datasource_name &#34匹配;

答案 1 :(得分:0)

我假设你的“java:comp / env / jdbc / Modeling”JNDI名称没有指向有效的数据源对象。

答案 2 :(得分:0)

从服务器设置中删除Jrebel插件后问题得以解决。 一些jrebel如何搞乱配置。

升级后的反叛配置现在工作正常。