gpt4 book ai didi

java - @EnableTransactionManagement 和 @Transaction 不适用于 Hibernate

转载 作者:行者123 更新时间:2023-12-02 13:07:26 24 4
gpt4 key购买 nike

我正在使用 MavenSpringHibernaterest API 制作应用程序。以下是我的项目的层次结构。持久性模块已编译并可供业务模块使用,并且该业务模块可供端点模块使用。非常简单。

我使用 spring 注释 而不是 xml,这是我试图实现的流程。

基于Web的应用程序调用rest API,在API中调用一个函数,在该函数中调用businessLogic模块,并且在该函数中module 调用持久性模块,其中编写了所有 DAO 及其实现。 每个模块都有自己的配置文件。也非常简单。

根据我所了解到的,我们使用标签@EnableTransactionManagement来让@Transaction工作。@Transaction 标签可以用在函数上,并且该函数将被视为单个事务,无论其中调用了多少次插入、更新.

问题:问题很简单,当我启动 apache 时,甚至当我调用稍后调用持久性来保存对象的 API 时,我都没有遇到任何异常。没有数据插入数据库,日志文件中也没有打印异常。

记住层次结构,以下是项目中使用的文件。

EndpointConfiguration.java

@Configuration
@EnableTransactionManagement
@PropertySource(value = { "classpath:persistence-hibernate.properties" })
public class EndpointConfiguration{

@Autowired
public org.springframework.core.env.Environment environment;


@Bean(name = "sessionFactory")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] { "com.product.persistence" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}

@Bean(name = "dataSource")
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
return dataSource;
}

private Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
return properties;
}

@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}

@Bean(name = "stakeHoldersBusinessLogic")
public IStakeHoldersBusinessLogic stakeHoldersBusinessLogic(){return new StakeHoldersBusinessLogicImpl(); }

@Bean(name = "daoFactoryCustom")
public DaoFactoryCustom daoFactoryCustom(){return new DaoFactoryCustomHbnImpl(); }

// some more beans

}

StakeHoldersEndpointImplRestController.java

@CrossOrigin(origins = "http://localhost:9090")
@RequestMapping(value = "/stakeHolders")
@RestController
public class StakeHoldersEndpointImplRestController implements IStakeHoldersEndpoint, InitializingBean {
@ResponseBody
@RequestMapping(value = "/createStakeHolder",
method = RequestMethod.POST,
headers = "Accept="+ MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public CreateStakeHolderResponse createStakeHolderEndpoint(@RequestBody CreateStakeHolderRequest request) {
LOG.trace("StakeHoldersEndpointImplRestController.createStakeHolder () - Start");

CreateStakeHolderResponse createStakeHolderResponse = new CreateStakeHolderResponse();

try{
createStakeHolderResponse = innerFunction(request);
}catch(Exception exception){
LOG.error("Exception Occurred : "+exception.getMessage());
}

LOG.trace("StakeHoldersEndpointImplRestController.createStakeHolder () - End");
return createStakeHolderResponse;
}

@Transactional
private CreateStakeHolderResponse innerFunction(CreateStakeHolderRequest request){

CreateStakeHolderResponse createStakeHolderResponse = new CreateStakeHolderResponse();

try {
createStakeHolderResponse = stakeHoldersBusinessLogic.createStakeHolderBusinessLogic(request);
}catch (Exception e){
LOG.error("Exception : ",e);
}
return createStakeHolderResponse;
}

BusinessLogicConfiguration.java

@Configuration
@EnableTransactionManagement
public class BusinessLogicConfiguration {

// some beans

}

StakeHoldersBusinessLogicImpl.java

public class StakeHoldersBusinessLogicImpl implements IStakeHoldersBusinessLogic, InitializingBean {

public CreateStakeHolderResponse createStakeHolderBusinessLogic(CreateStakeHolderRequest request) {
LOG.trace("StakeHoldersBusinessLogicImpl.createStakeHolderBusinessLogic () - Start");

CreateStakeHolderResponse createStakeHolderResponse = new CreateStakeHolderResponse(
IConstants.ERROR_CODE_BUSINESS_LOGIC_INITIATED_CODE , IConstants.ERROR_CODE_BUSINESS_LOGIC_INITIATED_STRING);

try{
//some logic to convert the request into stakeHolders, which is a Model bean mapped to a table
daoFactoryCustom.getStakeHoldersDAO().save(stakeHolders, 100L);

}catch(Exception exception){
LOG.error("Exception Occurred : ", exception);
}

LOG.trace("StakeHoldersBusinessLogicImpl.createStakeHolderBusinessLogic () - End");
return createStakeHolderResponse;
}

}

PersistenceConfiguration.java

@Configuration
@EnableTransactionManagement
public class PersistenceConfiguration {
// some beans
}

StakeHoldersDAOImpl.java

@Autowired(required = true)
SessionFactory sessionFactory;

public void save(T obj, Long creator) {
try{
getSession().save(obj);
}catch (Exception e){
LOG.error("Exception : ",e);
}
}

public final Session getSession() {
Session session;
try{
session = getSessionFactory().getCurrentSession();
}catch (HibernateException e){
session = sessionFactory.openSession();
}
return session;
}

我已经研究了一个多星期了,但找不到为什么会发生这种情况。此调用的日志跟踪如下。

18:09:14.653 [http-nio-8080-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor : 193 - Read [class com.product.contract.requests.CreateStakeHolderRequest] as "application/json" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@30b367c7]
18:09:14.719 [http-nio-8080-exec-2] TRACE org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod : 134 - Invoking [StakeHoldersEndpointImplRestController.createStakeHolderEndpoint] method with arguments [com.product.contract.requests.CreateStakeHolderRequest@17b06234]
18:09:14.719 [http-nio-8080-exec-2] TRACE com.product.endpoint.controller.impl.StakeHoldersEndpointImplRestController : 47 - StakeHoldersEndpointImplRestController.createStakeHolder () - Start
18:09:14.720 [http-nio-8080-exec-2] TRACE com.product.businesslogic.impl.StakeHoldersBusinessLogicImpl : 100 - StakeHoldersBusinessLogicImpl.createStakeHolderBusinessLogic () - Start
18:09:14.743 [http-nio-8080-exec-2] TRACE org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl : 1201 - Opening Hibernate Session. tenant=null, owner=null
18:09:14.912 [http-nio-8080-exec-2] TRACE org.hibernate.service.internal.AbstractServiceRegistryImpl : 229 - Initializing service [role=org.hibernate.stat.spi.StatisticsImplementor]
18:09:14.921 [http-nio-8080-exec-2] DEBUG org.hibernate.stat.internal.StatisticsInitiator : 82 - Statistics initialized [enabled=false]
18:09:14.934 [http-nio-8080-exec-2] TRACE org.hibernate.internal.SessionImpl : 281 - Opened Session [e4202ec0-7fd9-4333-9db4-efefa24d7c53] at timestamp: 14952857548
18:09:14.938 [http-nio-8080-exec-2] TRACE org.hibernate.event.internal.DefaultSaveOrUpdateEventListener : 163 - Saving transient instance
18:09:14.949 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL : 92 -
select
nextval ('pro5.entity_large')
18:09:14.950 [http-nio-8080-exec-2] DEBUG org.springframework.jdbc.datasource.DriverManagerDataSource : 142 - Creating new JDBC DriverManager Connection to [jdbc:postgresql://localhost:5432/postgres]
18:09:14.980 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 55 - Registering statement [select nextval ('pro5.entity_large')]
18:09:15.086 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 182 - Registering result set [org.postgresql.jdbc4.Jdbc4ResultSet@1d32dd3f]
18:09:15.092 [http-nio-8080-exec-2] DEBUG org.hibernate.id.enhanced.SequenceStructure : 101 - Sequence value obtained: 500046
18:09:15.093 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 91 - Releasing result set [org.postgresql.jdbc4.Jdbc4ResultSet@1d32dd3f]
18:09:15.093 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 132 - Closing result set [org.postgresql.jdbc4.Jdbc4ResultSet@1d32dd3f]
18:09:15.093 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 68 - Releasing statement [select nextval ('pro5.entity_large')]
18:09:15.093 [http-nio-8080-exec-2] DEBUG org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 73 - HHH000387: ResultSet's statement was not registered
18:09:15.093 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 148 - Closing prepared statement [select nextval ('pro5.entity_large')]
18:09:15.094 [http-nio-8080-exec-2] TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl : 263 - Starting afterQuery statement execution processing [AFTER_TRANSACTION]
18:09:15.095 [http-nio-8080-exec-2] DEBUG org.hibernate.event.internal.AbstractSaveEventListener : 118 - Generated identifier: 500046, using strategy: org.hibernate.id.enhanced.SequenceStyleGenerator
18:09:15.096 [http-nio-8080-exec-2] TRACE org.hibernate.event.internal.AbstractSaveEventListener : 157 - Saving [com.product.persistence.model.StakeHolders#500046]
18:09:15.116 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.ActionQueue : 244 - Adding an EntityInsertAction for [com.product.persistence.model.StakeHolders] object
18:09:15.120 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.IdentifierValue : 98 - ID unsaved-value strategy UNDEFINED
18:09:15.121 [http-nio-8080-exec-2] TRACE org.hibernate.persister.entity.AbstractEntityPersister : 1338 - Getting current persistent state for: [com.product.persistence.model.keyValuePair.CancellationReason#0]
18:09:15.122 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL : 92 -
select
cancellati_.id_cancellation,
cancellati_.dat_last_update as dat_last4_1_,
cancellati_.id_customer_last_update as id_custo5_1_,
cancellati_.str_cancellation_reason as str_canc6_1_
from
pro5.cancellation_reason cancellati_
where
cancellati_.id_cancellation=?
18:09:15.123 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 55 - Registering statement [select cancellati_.id_cancellation, cancellati_.dat_last_update as dat_last4_1_, cancellati_.id_customer_last_update as id_custo5_1_, cancellati_.str_cancellation_reason as str_canc6_1_ from pro5.cancellation_reason cancellati_ where cancellati_.id_cancellation=?]
18:09:15.127 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicBinder : 65 - binding parameter [1] as [INTEGER] - [0]
18:09:15.168 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 182 - Registering result set [org.postgresql.jdbc4.Jdbc4ResultSet@1f3e3b2c]
18:09:15.171 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicExtractor : 51 - extracted value ([dat_last4_1_] : [TIMESTAMP]) - [null]
18:09:15.172 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicExtractor : 51 - extracted value ([id_custo5_1_] : [BIGINT]) - [null]
18:09:15.174 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicExtractor : 61 - extracted value ([str_canc6_1_] : [VARCHAR]) - [Fraud]
18:09:15.175 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 91 - Releasing result set [org.postgresql.jdbc4.Jdbc4ResultSet@1f3e3b2c]
18:09:15.175 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 132 - Closing result set [org.postgresql.jdbc4.Jdbc4ResultSet@1f3e3b2c]
18:09:15.175 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 68 - Releasing statement [select cancellati_.id_cancellation, cancellati_.dat_last_update as dat_last4_1_, cancellati_.id_customer_last_update as id_custo5_1_, cancellati_.str_cancellation_reason as str_canc6_1_ from pro5.cancellation_reason cancellati_ where cancellati_.id_cancellation=0]
18:09:15.176 [http-nio-8080-exec-2] DEBUG org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 73 - HHH000387: ResultSet's statement was not registered
18:09:15.176 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 148 - Closing prepared statement [select cancellati_.id_cancellation, cancellati_.dat_last_update as dat_last4_1_, cancellati_.id_customer_last_update as id_custo5_1_, cancellati_.str_cancellation_reason as str_canc6_1_ from pro5.cancellation_reason cancellati_ where cancellati_.id_cancellation=0]
18:09:15.176 [http-nio-8080-exec-2] TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl : 263 - Starting afterQuery statement execution processing [AFTER_TRANSACTION]
18:09:15.177 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.IdentifierValue : 98 - ID unsaved-value strategy UNDEFINED
18:09:15.177 [http-nio-8080-exec-2] TRACE org.hibernate.persister.entity.AbstractEntityPersister : 1338 - Getting current persistent state for: [com.product.persistence.model.keyValuePair.Cities#0]
18:09:15.178 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL : 92 -
select
cities_.id_city,
cities_.dat_last_update as dat_last4_2_,
cities_.id_customer_last_update as id_custo5_2_,
cities_.str_city as str_city6_2_
from
pro5.cities cities_
where
cities_.id_city=?
18:09:15.178 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 55 - Registering statement [select cities_.id_city, cities_.dat_last_update as dat_last4_2_, cities_.id_customer_last_update as id_custo5_2_, cities_.str_city as str_city6_2_ from pro5.cities cities_ where cities_.id_city=?]
18:09:15.179 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicBinder : 65 - binding parameter [1] as [BIGINT] - [0]
18:09:15.199 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 182 - Registering result set [org.postgresql.jdbc4.Jdbc4ResultSet@7b2493e9]
18:09:15.200 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicExtractor : 51 - extracted value ([dat_last4_2_] : [TIMESTAMP]) - [null]
18:09:15.200 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicExtractor : 51 - extracted value ([id_custo5_2_] : [BIGINT]) - [null]
18:09:15.201 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicExtractor : 61 - extracted value ([str_city6_2_] : [VARCHAR]) - [Lahore]
18:09:15.201 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 91 - Releasing result set [org.postgresql.jdbc4.Jdbc4ResultSet@7b2493e9]
18:09:15.201 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 132 - Closing result set [org.postgresql.jdbc4.Jdbc4ResultSet@7b2493e9]
18:09:15.202 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 68 - Releasing statement [select cities_.id_city, cities_.dat_last_update as dat_last4_2_, cities_.id_customer_last_update as id_custo5_2_, cities_.str_city as str_city6_2_ from pro5.cities cities_ where cities_.id_city=0]
18:09:15.202 [http-nio-8080-exec-2] DEBUG org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 73 - HHH000387: ResultSet's statement was not registered
18:09:15.202 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 148 - Closing prepared statement [select cities_.id_city, cities_.dat_last_update as dat_last4_2_, cities_.id_customer_last_update as id_custo5_2_, cities_.str_city as str_city6_2_ from pro5.cities cities_ where cities_.id_city=0]
18:09:15.202 [http-nio-8080-exec-2] TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl : 263 - Starting afterQuery statement execution processing [AFTER_TRANSACTION]
18:09:15.203 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.IdentifierValue : 98 - ID unsaved-value strategy UNDEFINED
18:09:15.203 [http-nio-8080-exec-2] TRACE org.hibernate.persister.entity.AbstractEntityPersister : 1338 - Getting current persistent state for: [com.product.persistence.model.StakeHoldersType#10]
18:09:15.203 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL : 92 -
select
stakeholde_.id_stake_holder_type,
stakeholde_.id_str_role as id_str_r3_25_,
stakeholde_.str_stake_holder_desc as str_stak2_25_
from
pro5.stake_holders_type stakeholde_
where
stakeholde_.id_stake_holder_type=?
18:09:15.204 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 55 - Registering statement [select stakeholde_.id_stake_holder_type, stakeholde_.id_str_role as id_str_r3_25_, stakeholde_.str_stake_holder_desc as str_stak2_25_ from pro5.stake_holders_type stakeholde_ where stakeholde_.id_stake_holder_type=?]
18:09:15.205 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicBinder : 65 - binding parameter [1] as [BIGINT] - [10]
18:09:15.208 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 182 - Registering result set [org.postgresql.jdbc4.Jdbc4ResultSet@3c215e9d]
18:09:15.209 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicExtractor : 51 - extracted value ([id_str_r3_25_] : [VARCHAR]) - [null]
18:09:15.210 [http-nio-8080-exec-2] TRACE org.hibernate.type.descriptor.sql.BasicExtractor : 61 - extracted value ([str_stak2_25_] : [VARCHAR]) - [Transport]
18:09:15.210 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 91 - Releasing result set [org.postgresql.jdbc4.Jdbc4ResultSet@3c215e9d]
18:09:15.210 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 132 - Closing result set [org.postgresql.jdbc4.Jdbc4ResultSet@3c215e9d]
18:09:15.211 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 68 - Releasing statement [select stakeholde_.id_stake_holder_type, stakeholde_.id_str_role as id_str_r3_25_, stakeholde_.str_stake_holder_desc as str_stak2_25_ from pro5.stake_holders_type stakeholde_ where stakeholde_.id_stake_holder_type=10]
18:09:15.212 [http-nio-8080-exec-2] DEBUG org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 73 - HHH000387: ResultSet's statement was not registered
18:09:15.212 [http-nio-8080-exec-2] TRACE org.hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl : 148 - Closing prepared statement [select stakeholde_.id_stake_holder_type, stakeholde_.id_str_role as id_str_r3_25_, stakeholde_.str_stake_holder_desc as str_stak2_25_ from pro5.stake_holders_type stakeholde_ where stakeholde_.id_stake_holder_type=10]
18:09:15.212 [http-nio-8080-exec-2] TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl : 263 - Starting afterQuery statement execution processing [AFTER_TRANSACTION]
18:09:15.213 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.ActionQueue : 257 - Adding insert with no non-nullable, transient entities: [EntityInsertAction[com.product.persistence.model.StakeHolders#500046]]
18:09:15.213 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.ActionQueue : 280 - Adding resolved non-early insert action.
18:09:15.216 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.IdentifierValue : 98 - ID unsaved-value strategy UNDEFINED
18:09:15.216 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.IdentifierValue : 98 - ID unsaved-value strategy UNDEFINED
18:09:15.216 [http-nio-8080-exec-2] TRACE org.hibernate.engine.spi.IdentifierValue : 98 - ID unsaved-value strategy UNDEFINED
18:09:15.225 [http-nio-8080-exec-2] TRACE com.product.businesslogic.impl.StakeHoldersBusinessLogicImpl : 152 - StakeHoldersBusinessLogicImpl.createStakeHolderBusinessLogic () - End
18:09:15.225 [http-nio-8080-exec-2] TRACE com.product.endpoint.controller.impl.StakeHoldersEndpointImplRestController : 82 - StakeHoldersEndpointImplRestController.createStakeHolder () - End
18:09:15.226 [http-nio-8080-exec-2] TRACE org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod : 138 - Method [createStakeHolderEndpoint] returned [com.product.contract.responses.CreateStakeHolderResponse@6aac8e42]
18:09:15.301 [http-nio-8080-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor : 226 - Written [com.product.contract.responses.CreateStakeHolderResponse@6aac8e42] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@30b367c7]
18:09:15.302 [http-nio-8080-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet : 1036 - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
18:09:15.302 [http-nio-8080-exec-2] TRACE org.springframework.web.servlet.DispatcherServlet : 1059 - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@70e62c16
18:09:15.302 [http-nio-8080-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet : 997 - Successfully completed request
18:09:15.302 [http-nio-8080-exec-2] TRACE org.springframework.web.context.support.AnnotationConfigWebApplicationContext : 363 - Publishing event in WebApplicationContext for namespace 'dispatcher-servlet': ServletRequestHandledEvent: url=[/endpoint/stakeHolders/createStakeHolder]; client=[0:0:0:0:0:0:0:1]; method=[POST]; servlet=[dispatcher]; session=[null]; user=[null]; time=[807ms]; status=[OK]
18:09:15.302 [http-nio-8080-exec-2] TRACE org.springframework.web.context.support.AnnotationConfigWebApplicationContext : 363 - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/endpoint/stakeHolders/createStakeHolder]; client=[0:0:0:0:0:0:0:1]; method=[POST]; servlet=[dispatcher]; session=[null]; user=[null]; time=[807ms]; status=[OK]

我在这一切中做错了什么,任何帮助都会很棒。

谢谢

伊沙德·艾哈迈德。

最佳答案

首先,@Transactional 不适用于代理模式(默认)下的私有(private)方法。

其次,使用 @Transactional 注释 Controller 方法有点不寻常。通常您用它来注释服务类(如果您只有 DAO 而没有服务,则使用 DAO 类)。

所以我建议如下:

  1. 使用 @Transactional 注释 StakeHoldersBusinessLogicImpl(因为这似乎是您的服务)
  2. 从 Controller 方法中删除 @Transactional

关于java - @EnableTransactionManagement 和 @Transaction 不适用于 Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44087481/

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