PDA

View Full Version : MongoDB Lifecycle events not being initialized



bjornharvold
Jun 22nd, 2011, 12:57 PM
After I register:
<bean class="com.xxx.event.OnAfterConvertUserEventListener"/>

I would expect the below method "userRepository.findByUsername" to initiate the aforementioned bean. It doesn't. In the docs, it says that if I use findOne(), it will pick it up.

It does work when I call userRepository.findAll().

@Repository("userRepository")
public class MongoUserRepository extends QueryDslMongoRepository<User, String> implements UserRepository {
QUser user = QUser.user;

@Autowired
public MongoUserRepository(MongoTemplate mongoTemplate) {
super(new MappingMongoEntityInformation<User, String>(
new BasicMongoPersistentEntity<User>(
new ClassTypeInformation<User>(User.class))
), mongoTemplate
);
}

@Override
public User findByUsername(String username) {
return findOne(user.username.eq(username));
}
}

Interface:
public interface UserRepository extends PagingAndSortingRepository<User, String>, QueryDslPredicateExecutor<User> {

User findByUsername(String username);
}

bjornharvold
Jun 22nd, 2011, 12:59 PM
Created ticket here: https://jira.springsource.org/browse/DATADOC-179

bjornharvold
Jun 22nd, 2011, 08:57 PM
It does work if I do not implement my own Repository but instead use <mongo:repositories base-package="com.xxxx.repository"/>