Announcement Announcement Module
Collapse
No announcement yet.
java.lang.IllegalArgumentException: Transaction must be running with JdbcMutableAclSe Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.IllegalArgumentException: Transaction must be running with JdbcMutableAclSe

    (My apology for lifting some of this from

    I'm adding ACLs to an existing spring hibernate project and I am getting a:

    Code:
    java.lang.IllegalArgumentException: Transaction must be running
    exception in the following method:

    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);
    		}
    	}
    The exception is being thrown by the JdbcMutableAclService. You can see the assert line below:

    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;
        }
    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.

    I have

    Code:
    <tx:annotation-driven />
    and

    Code:
       <bean
          id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"
       >
          <property
             name="sessionFactory"
             ref="sessionFactory" />
       </bean>
    in my spring application context, but I wonder if I also need to define an
    Code:
    org.springframework.jdbc.datasource.DataSourceTransactionManager
    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?

  • #2
    Hello

    java.lang.IllegalArgumentException: Transaction must be running
    Is that all error stack trace?, post all, other inner details would be more useful that the first shown in the error stack trace

    Comment


    • #3
      Hi,

      I've got the same exception with the same configuration and I would now how you resolved it ?
      Did you used a JtaTransactionManager ?

      Thx

      Comment


      • #4
        Originally posted by theleek View Post
        Hi,

        I've got the same exception with the same configuration and I would now how you resolved it ?
        Did you used a JtaTransactionManager ?

        Thx
        The error you mentioned only happens when the sid is not present in the acl_sid table and is inserted by Spring ACL automatically. Try adding the rows manually and then rerun the code. This worked for me.

        Refer http://forum.springsource.org/showth...ust-be-running

        Comment


        • #5
          As an FYI, I find this error to be very misleading: "Transaction must be running".

          But, the following did lead me in the right direction:

          The error you mentioned only happens when the sid is not present in the acl_sid table and is inserted by Spring ACL automatically. Try adding the rows manually and then rerun the code. This worked for me.
          I had canned rows already in my database for ACL_SID, ACL_CLASS, etc. but I was using the number 1 to represent TRUE instead of 'true'. The AclSecurityUtil I have based on an example out on link was creating new rows for each user that I had already in ACL_SID. Each new row was identical to its existing counterpart except for the "PRINCIPAL" column which had 'true' instead of '1'. Also, I noticed ACL_OBJECT_IDENTITY.ENTRIES_INHERITING should use 'true' instead of '1'.

          Hope this helps someone!

          Comment

          Working...
          X