gpt4 book ai didi

java - 不支持的操作异常 : The application must supply JDBC connections JPA Hibernate Spring JDBC

转载 作者:行者123 更新时间:2023-11-30 10:33:26 25 4
gpt4 key购买 nike

当我尝试开始交易时

entityManager.getTransaction().begin();

在 AbstractDao 中,我得到

java.lang.UnsupportedOperationException: The application must supply JDBC connections

我的persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value = "create-drop"/>
</properties>
</persistence-unit>
</persistence>

我的 hibernate 属性

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ewp?createIfNotExist=true
jdbc.username=root
jdbc.password=root
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=false
hibernate.hbm2ddl.auto=create-drop

EntityManagerFactory bean :

    @Bean
public EntityManagerFactory entityManagerFactory(){
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("pu");
return entityManagerFactory;
}

实体管理器 bean:

@Bean
public EntityManager entityManager(){
return entityManagerFactory.createEntityManager();
}

最佳答案

来自 hibernate site ,您的属性名称看起来不正确。应该是,

"hibernate.connection.driver_class" for JDBC driver class
"hibernate.connection.url" for JDBC URL
"hibernate.connection.username" for database user
"hibernate.connection.password" for database user password

更正您的属性名称。

关于java - 不支持的操作异常 : The application must supply JDBC connections JPA Hibernate Spring JDBC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42218137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com