Hi, thanks for the tip, it works when I use the code from SyncJob. I think it had to do with the securitysetup (setup dummy admin user) & reading in the userTO.
regards Bob On 3 July 2012 14:48, Francesco Chicchiriccò <[email protected]> wrote: > On 03/07/2012 14:27, Bob Lannoy wrote: >> >> Hi, >> >> I've written a job to delete users in a specific status (toBeRemoved). >> Unfortunately I get a nullpointer exception. >> This is what I do: >> >> NodeCond searchCond = new NodeCond(); >> SyncopeUserCond syncopeUserCond = new SyncopeUserCond(); >> syncopeUserCond.setSchema("status"); >> syncopeUserCond.setExpression("toBeRemoved"); >> >> syncopeUserCond.setType(org.apache.syncope.client.search.AttributeCond.Type.EQ); >> searchCond.setSyncopeUserCond(syncopeUserCond); >> >> searchCond.setType(org.apache.syncope.client.search.NodeCond.Type.LEAF); >> >> List<SyncopeUser> >> >> users=searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), >> searchCond); >> >> for (SyncopeUser user : users){ >> userDAO.delete(user.getId()); >> } >> >> The nullpointer exception occurs on the delete. In that method it >> looks for memberships but those are empty, thus the nullpointer. >> When I look at the user-object in debug mode I see that even the >> attributes are not present in the object. So it seems that I do not >> get a complete object back from the search. Only the core attributes >> like username, status, password, token >> The same search in console gives me everything (firstname, last name, ...) >> >> What am I doing wrong? > > > As far as I can imagine, you are hitting a known JPA issue with lazy loading > and transactions: to make it short, the SyncopeUser object that you get is > not "complete", but some collections (i.e. JPA relations) are populated upon > reading, and this can only happen in a valid transactional scope. > > When you call UserDAO.delete(SyncopeUser), this will attempt to use the > provided object for operations, but since you are outside a transactional > scope, you'll hit the NPE. > > Take a look at SyncJob: it extends AbstractTaskJob (like your job, I > suppose) and performs almost any operation on SyncopeUser objects by > delegating to other @Autowired objects living in a transactional scope: look > in particular the deleteUsers() method. > > Hope this helps. > Regards. > > -- > Francesco Chicchiriccò > > ASF Member, Apache Cocoon PMC and Apache Syncope PPMC Member > http://people.apache.org/~ilgrosso/ >
