(My apology for lifting some of this from
I'm adding ACLs to an existing spring hibernate project and I am getting a:
exception in the following method:Code:java.lang.IllegalArgumentException: Transaction must be running
The exception is being thrown by the JdbcMutableAclService. You can see the assert line below:Code:@Override @Transactional(readOnly=false) public void createOrUpdateUser(User user) { if (user.getId() == null) { entityDao.create(user); ObjectIdentity oid = new ObjectIdentityImpl(User.class, user.getId()); MutableAcl acl = aclService.createAcl(oid); acl.insertAce(0, BasePermission.DELETE, new GrantedAuthoritySid("ROLE_ROOT"), true); aclService.updateAcl(acl); } else { entityDao.update(user); } }
Why am I being told there's no Transaction running when the method is annotated with @Transactional? All the hibernate transactions work normally it's just when I try to add ACLs that I get this error.Code:protected Long createOrRetrieveSidPrimaryKey(Sid sid, boolean allowCreate) { Assert.notNull(sid, "Sid required"); String sidName = null; boolean sidIsPrincipal = true; if (sid instanceof PrincipalSid) { sidName = ((PrincipalSid) sid).getPrincipal(); } else if (sid instanceof GrantedAuthoritySid) { sidName = ((GrantedAuthoritySid) sid).getGrantedAuthority(); sidIsPrincipal = false; } else { throw new IllegalArgumentException("Unsupported implementation of Sid"); } List<Long> sidIds = jdbcTemplate.queryForList(selectSidPrimaryKey, new Object[] {Boolean.valueOf(sidIsPrincipal), sidName}, Long.class); if (!sidIds.isEmpty()) { return sidIds.get(0); } if (allowCreate) { jdbcTemplate.update(insertSid, new Object[] {Boolean.valueOf(sidIsPrincipal), sidName}); Assert.isTrue(TransactionSynchronizationManager.isSynchronizationActive(), "Transaction must be running"); return new Long(jdbcTemplate.queryForLong(sidIdentityQuery)); } return null; }
I have
andCode:<tx:annotation-driven />
in my spring application context, but I wonder if I also need to define anCode:<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" > <property name="sessionFactory" ref="sessionFactory" /> </bean>too? That would necessitate two difference methods with two difference @Transactional lines that reference the two difference managers. Reading the hibernate manager seems to suggest that it should be usable in this situation (for direct JDBC stuff). How do I get it to work though?Code:org.springframework.jdbc.datasource.DataSourceTransactionManager


Reply With Quote
