Spring Boot JPA Hibernate+;persistence.xml不插入
我有一个插入不工作的问题。阅读(选择)工作正常。但是,在@Transactional方法的末尾没有执行插入。即使我看到实体管理器上调用了事务提交/关闭。我尝试了不同的配置,但仍然无法在事务结束时使记录(插入)正常工作。我没有看到任何错误被生成。我启用了hibernate.transaction调试,没有看到任何hibernate事务消息 我使用Tomcat将Spring boot(.1.5.3)作为WAR可执行文件运行。我在Spring Boot上使用persistence.xml(hibernate5 ddl maven plugin<在构建期间生成SQL ddl所需的persistence.xml) 在调试过程中,我看到JpaTransactionManager创建了新事务(创建了名为…打开了新EntityManager,,,将JPA事务公开为JDBC事务),加入了其他@Transactional方法(找到了线程绑定的EntityManager…参与了现有事务)并提交了TX(启动事务提交…在EntityManager上提交JPA事务),并关闭JPA EM(关闭JPA EntityManager)。这一切都是根据@Transactional规范进行的。但是,记录没有插入到数据库中。我没有看到任何hibernate事务消息 下面是我的一些配置 persistence.xml:Spring Boot JPA Hibernate+;persistence.xml不插入,spring,hibernate,transactions,persistence.xml,hikaricp,Spring,Hibernate,Transactions,Persistence.xml,Hikaricp,我有一个插入不工作的问题。阅读(选择)工作正常。但是,在@Transactional方法的末尾没有执行插入。即使我看到实体管理器上调用了事务提交/关闭。我尝试了不同的配置,但仍然无法在事务结束时使记录(插入)正常工作。我没有看到任何错误被生成。我启用了hibernate.transaction调试,没有看到任何hibernate事务消息 我使用Tomcat将Spring boot(.1.5.3)作为WAR可执行文件运行。我在Spring Boot上使用persistence.xml(hibern
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<!--
This file is needed to generate the DDL.
-->
<persistence-unit
name="EzListaPersistence"
transaction-type="RESOURCE_LOCAL">
<description>
The set of entity types that can be managed by a
given entity manager is defined by a persistence unit. A
persistence unit defines the set of all classes that are
related or grouped by the application, and which must be
collocated in their mapping to a single data store.
</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!--
List of fully qualified Entity Classes
-->
<class>com.ezlista.domain.account.Account</class>
...... NOT DISPLAYED ....
<class>com.ezlista.domain.useraccount.Notification</class>
<properties>
<!-- Hibernate Connection Settings -->
<property
name="hibernate.connection.provider_class"
value="org.hibernate.hikaricp.internal.HikariCPConnectionProvider" />
<property
name="hibernate.hikari.dataSourceClassName"
value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
<property
name="hibernate.hikari.dataSource.url"
value="jdbc:mysql://localhost:3306/EZLISTA?verifyServerCertificate=false&useSSL=false" />
<property
name="hibernate.hikari.dataSource.user"
value="rubens" />
<property
name="hibernate.hikari.dataSource.password"
value="***MASKED***" />
<property
name="hibernate.hikari.dataSource.cachePrepStmts"
value="true" />
<property
name="hibernate.hikari.dataSource.prepStmtCacheSize"
value="250" />
<property
name="hibernate.hikari.dataSource.prepStmtCacheSqlLimit"
value="2048" />
<property
name="hibernate.hikari.minimumIdle"
value="5" />
<property
name="hibernate.hikari.maximumPoolSize"
value="10" />
<property
name="hibernate.hikari.idleTimeout"
value="30000" />
<!-- SQL Settings -->
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.show_sql"
value="false" />
<property name="hibernate.format_sql"
value="true" />
<property name="hibernate.use_sql_comments"
value="false" />
<property name="hibernate.ddl-auto"
value="none" />
<!-- Hibernate Cache Settings -->
<property name="hibernate.javax.cache.provider"
value="org.ehcache.jsr107.EhcacheCachingProvider" />
<property name="hibernate.cache.region.factory_class"
value="org.hibernate.cache.jcache.JCacheRegionFactory" />
<property name="hibernate.cache.use_second_level_cache"
value="true" />
<property name="hibernate.cache.use_query_cache"
value="false" />
<property name="hibernate.cache.use_structured_entries"
value="true" />
<property name="hibernate.cache.use_minimal_puts"
value="true" />
</properties>
</persistence-unit>
宾果!!!!
我用@PersistenceContext(unitName=PERSISTENCE\u UNIT\u NAME)注释了我的EntityManager,之后它就可以工作了
下面是修复上述问题的代码。请注意下面的@PersistenceContext注释(这就是修复问题的原因)。在我在em上使用@Inject注释之前
@PersistenceContext(unitName = PERSISTENCE_UNIT_NAME)
protected EntityManager em;
宾果!!!!
我用@PersistenceContext(unitName=PERSISTENCE\u UNIT\u NAME)注释了我的EntityManager,之后它就可以工作了
下面是修复上述问题的代码。请注意下面的@PersistenceContext注释(这就是修复问题的原因)。在我在em上使用@Inject注释之前
@PersistenceContext(unitName = PERSISTENCE_UNIT_NAME)
protected EntityManager em;
你好,鲁本斯·戈麦斯,你能看看我的代码,看看我做错了什么吗?你好,鲁本斯·戈麦斯,你能看看我的代码,看看我做错了什么吗?