【java – 多个实例并行命中@Transactional注释方法时会发生什么?】教程文章相关的互联网学习教程文章

java-Spring @Transactional是否使用任何Hibernate缓存?【代码】

@Transactional public MyEntity getEntity(long id) {return dao.findOne(id);//or select and update as well }每次我调用事务方法时:我是否将从休眠中获取任何缓存的实体(第一次除外)?还是我总是从数据库中获取新鲜的实体? 这一点很重要,因为我将拥有两个共享相同数据库的独立应用程序,并且我想确保休眠状态不返回任何缓存的实体,而另一个应用程序可能已经在后台更新了数据库中的同一实体.解决方法:如果这是服务层的事务边界...

java – 当@ActiveProfiles(“test”)时,如何忽略特定方法的spring @Transactional注释【代码】

在集成测试期间,我需要忽略以下@Transactional注释.@Service public class MyClass {@Transactional(propagation = Propagation.NEVER)public void doSomething() {// do something that once in production can not be inside a transaction (reasons are omitted)}}问题是我的所有测试都是在默认情况下回滚的事务中执行的.当该方法在测试范围内运行时(@ActiveProfiles(“test”))允许它在事务内执行时,我怎么能忽略该方法的@Tran...

[Spring Java] identify transactional business services boundaries【代码】

If one request failed, we want to keep database untouched as if the request never happen. Spring makes it easy to add:@TransactionalTo the method or Class: For example:@Service @Transactional public class TourRatingService {private TourRatingRepository tourRatingRepository;private TourRepository tourRepository;/*** Construct TourRatingService** @param tourRatingRepository Tour Rating Repositor...

java-Spring @transactional与mode = aspectj行为异常【代码】

几天来,我一直在尝试使Spring事务在我的应用程序中正常运行,现在我无处可寻,只能向社区寻求帮助.在此先感谢您的帮助. 我的应用程序有特定的要求,我需要使用@Transactional注释一个受保护的重写方法,并从抽象父类中调用此方法.根据我的阅读,我不能使用代理,而必须使用mode = aspectj. 首先,一些配置:<bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="data...

java-私有方法上的@Transactional传播【代码】

我有以下代码:@Service public class MyService implements IMyService {@InjectIAnotherService anotherService;// injects go here// some code@Transactional(isolation=Isolation.SERIALIZABLE)public Result myMethod() {// stuff done herereturn this.myPrivateMethod()} private Result myPrivateMethod() {// stuff done here// multiple DAO SAVE of anObjectanotherService.processSomething(anObject);return result;...

Java Spring 4 @Transactional嵌套事务问题【代码】

我有以下课程:@Transactional public class MyClass{@Transactional(propagation=Propagation.REQUIRES_NEW)public void method1(){....myDao.update(entity);}public void method2(){method1(); //I need to be sure that data was persisted to DB and find the entity by id MyEntity ent=myDao.find(entityId);//entity is not updated here}}但实际上我无法在method2中从数据库读取更新的实体.如何实现呢?在...

java-使用Spring @Transactional的TestNG多线程测试【代码】

我正在使用TestNG,以AbstractTransactionalTestNGSpringContextTests作为基类来测试持久性Spring模块(JPA Hibernate). @ Autowired,@ TransactionConfiguration,@ Transactional的所有重要部分都可以正常工作. 当我尝试在带有threadPoolSize = x,invocationCount = y TestNG批注的并行线程中运行测试时,就会出现问题.WARNING: Caught exception while allowing TestExecutionListener [org.springframework.test.context.transacti...

从Java手动使用@Transactional方法创建Spring @Service实例【代码】

假设有@Service和@Repository接口,如下所示:@Repository public interface OrderDao extends JpaRepository<Order, Integer> {}public interface OrderService {void saveOrder(Order order);}@Service public class OrderServiceImpl implements OrderService {@Autowiredprivate OrderDao orderDao;@Override@Transactionalpublic void saveOrder(Order order) {orderDao.save(order);}}这是工作应用程序的一部分,所有内容都配置...

java-@Transactional,方法内部的方法【代码】

我有一个带有调用另一个方法的方法的服务.在第一种方法中,我仅使用SELECT执行查询,但它们必须查看在第二种方法中完成的INSERTS和UPDATES. 然后,我必须处理交易.我正在使用Spring,因此可以使用@Transactional批注. 以下哪个选项似乎更适合您? 选项A@Transactional public void generate(){// selectssave(a);// more selects }@Transactional public void save(Object a){//save the object }选项Bpublic void generate(){// selec...

java-在@Transactional内的try-catch中提交更改【代码】

考虑一下我有一个方法以ActiveRecord模式样式执行一些工作和日志记录机制:@Transactional public void doSmt() {try {someOperation(); // can throw exceptionLogger.logIntoDb(); // if everything is OK} catch {Exception e} {Logger.logIntoDbWithException(e.getMessage()); // log error into dbthrow new MyCustomException(e);} }public static void logIntoDbWithException(String message) {final LogEntry logEntry =...

java-如何在m​​ybatis-spring中使用@Transactional批注?【代码】

我尝试使用mybatis-spring依赖项在spring和mybatis中使用@Transactional批注.这是服务层.@Service public class OracleService {@Autowiredprivate TestMapper mapper;@Autowiredprivate PlatformTransactionManager transactionManager;@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class,value = "transactionManager")void insert1() {TestModel testModel = new TestModel(1, "title1", "conte...

java-@Transactional注释是否避免并发访问业务层方法【代码】

对于业务/服务层中@Transactional注释的用法,我还不清楚. 我的问题是,与业务层中的ISOLATION_SERIALIZABLE一起使用时,@ Transactional注释是否可以保证不允许对特定方法进行并发访问?@Transactional(isolation = Isolation.SERIALIZABLE) public void businessMethod() {// calls subBusinessMethodsubBusinessMethod();---------------------------------------------}想象一下subBusinessMethod调用DAO层来执行一些数据库事务.调...

java-@Transactional在Spring Web MVC中不起作用?【代码】

尽管在方法中添加了@Transactional,但我在spring mvc中调用EntityManager.persist()时会出现异常,它可以在不集成spring mvc的情况下工作:HTTP ERROR 500Problem accessing /ssshp/addDept/wwewd. Reason:No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call Caused by:javax.persistence.TransactionRequiredException: No EntityManager with actual transaction ...

java – synchronized方法还是使用spring @transactional?【代码】

我有一个方法将用于发送电子邮件.我想锁定这个方法,所以每次只有一个线程可以接受它,并且其余的池同时存在.我应该同步方法还是使用spring @transactional PROPAGATION_REQUIRED? 在我的服务层//each time use new thread to send out emailpublic void sendThroughSMTP(List<String> emails,String subject,String content){//each time will open and sent through port 25. dont u think this will caused too many threads s...

java – Spring @Transactional方法中没有事务启动【代码】

我在使用Spring(3.0.5),Hibernate(3.6.0)和Wicket(1.4.14)开发应用程序时遇到了奇怪的问题.问题是:我无法将任何对象保存或修改为数据库.通过’不能’,我的意思是对象的所有更改或对EntityManager.persist(foo)的调用都被简单地,默默地忽略.选择工作. 示例案例很简单 – 在一些wicket页面上我尝试将对象保存到数据库中,如下所示public class ComicDetailsPage extends PublicBasePage {@Override protected void onConfigure() {Sy...