草庐IT

transaction_amount

全部标签

java - JPA+Hibernate+@Transactional注解的spring事务支持的奇怪行为

我在相对简单的用例上发现了非常奇怪的行为,可能因为对spring@Transactional性质的了解不深,我无法理解它,但这很有趣。我有一个简单的用户dao,它扩展了springJpaDaoSupport类并包含标准保存方法:@TransactionalpublicUsersave(Useruser){getJpaTemplate().persist(user);returnuser;}如果在我向同一个类添加新方法之前工作正常:UsergetSuperUser(),此方法应该返回isAdmin==true的用户,如果数据库中没有super用户,方法应该创建一个。这就是它的样子:pub

java - 打包应用程序时获取包 org.springframework.transaction.annotation 不存在错误

我是Spring世界的新手。我使用Spring3.2和Hibernate4.1.9开发了一个DAO,但我注意到一件奇怪的事情。除spring-aop模块外,所有使用的Spring相关的依赖都属于3.2.1版本。对于此模块,我必须使用3.2.0版本,因为如果我在dao类实现中使用3.2.1,则找不到此导入:org.springframework.transaction.annotation.Transactional这是我原来的pom.xml文件(效果很好):4.0.0org.andrea.myexampleHibernateOnSpring0.0.1-SNAPSHOTjarHibern

java - 如何避免在服务类中重复 DAO 方法? @Transactional 注释 DAO 和服务类 - 这是可以接受的做法吗?

我知道最佳实践是同时拥有服务层和Dao层,并在服务层添加@Transactional注解。但在我的例子中,这意味着我的大部分服务类都是为了重复DAO方法而创建的……这很烦人。例如。publicinterfaceFooDAO{publicListlist(intcathegoryId);publicListlist(intcathegoryId,intownerId);}@Service@TransactionalpublicclassFooService{protected@AutowiredFooDAOdao;publicListlist(intcathegoryId){dao.li

java - SQL Server 2012 上的 "New request is not allowed to start because it should come with valid transaction descriptor"

编辑:找到解决方案,往下看。我们有一个Web应用程序,它调用存储在SqlServer2012数据库中的View的选择。此查询因错误而失败"Newrequestisnotallowedtostartbecauseitshouldcomewithvalidtransactiondescriptor"此问题仅发生在单个客户数据库上,在所有其他客户模式上执行的相同查询运行正常。在SSMS中对受影响模式自行执行的查询运行正常,仅在该特定模式上的应用程序中失败。SELECT语句是这样的:selectdistinctclienti.numeroCliente,clienti.ragioneSocia

java - @Transactional 在 CDI Bean 的基类中被忽略

具有以下相当简单的代码和正确配置的基于JTA的持久性上下文:abstractclassAbstractRepository{@PersistenceContextprotectedEntityManagerem;@Transactionalpublicsynchronizedvoidpersist(Eentity){em.persist(entity);em.flush();}}@ApplicationScopedclassMyEntityRepositoryextendsAbstractRepository{}我在调用MyEntityRepository.persist()时遇到以下

java - Spring 数据 : rollback transaction on retry

有一个实体:@EntityclassA{...@Versionintversion;}A以乐观方式实现的实例更新:@Transactional(rollbackFor={StaleStateException.class})@Retryable(value={StaleStateException.class})publicvoidupdateA(){Aa=findA();Bb=newB();//Update"a"somehowa.update();//"b"issavedoneachretry!save(b);}正如评论中所述,当StaleStateException发生时,事务似乎

java - Guice @Transactional 不启动事务

我已经开始使用Guice方法级事务,如所述here.我有这样的消息@InjectprivateEntityManagerentityManager;@TransactionalpublicUserSessioncreateSession(Useruser,Stringbrowser){UserSessionsession=newUserSession(user,browser);entityManager.persist(session);}从简短的描述来看,我认为wis应该足够了。但是我得到一个错误,因为没有交易开始。仅当我自己开始并提交时它才有效。该对象是由Guice在我的应用程序

java - hibernate 异常 : Could not obtain transaction-synchronized Session for current thread

我遇到错误:Exceptioninthread"main"org.hibernate.HibernateException:Couldnotobtaintransaction-synchronizedSessionforcurrentthread主要ppService.deleteProductPart(cPartId,productId);@Service("productPartService")@OverridepublicvoiddeleteProductPart(intcPartId,intproductId){productPartDao.deleteProductPart

java - @Transactional (noRollbackFor=RuntimeException.class) 不会阻止在 RuntimeException 上回滚

@Transactional(noRollbackFor=RuntimeException.class)publicvoidmethodA(Entitye){service.methodB(e);}---以下服务方式---@Transactional(propagation=Propagation.REQUIRES_NEW,noRollbackFor=RuntimeException.class)publicvoidmethodB(Entitye){dao.insert(e);}当methodB()中的dao.insert(e)导致主键冲突并抛出ConstraintViolationE

java - 自定义 Spring AOP Around + @Transactional

我实现了自定义Around以匹配自定义注释。我希望自定义在外部@Transactional中执行。不幸的是,这似乎不起作用。(AOP正在运行。我看到显示它的堆栈跟踪)。堆栈跟踪显示我的AOP在(记录器)之前执行,MyBatissession开始一个事务,MyBatis关闭事务,Spring关闭事务然后我的AOP完成。我认为让我的AOP实现Ordered会有所帮助。我将返回的值设置为1。我使用.这没有用。我认为这是因为我误解了Spring的命令方式。AdviceorderingWhathappenswhenmultiplepiecesofadviceallwanttorunatthesa