在Roo 2.0中我想使用JPA Query Method

时间:2017-08-11 03:28:09

标签: java spring-data-jpa spring-roo

我计划编写像

这样的查询方法
/**
 * TODO Auto-generated method documentation
 * 
 * @param entity
 * @return EventExecute
 */
@Transactional
@Autowired
public EventExecute save(EventExecute entity) {
    String eventKey = entity.getEventKey();

    StepDefinitionRepository sdRepository;

    List<StepDefinition> stepDefinitions = sdRepository.findByEventKeyAllIgnoreCaseOrderBySequenceAsc(eventKey);

    return getEventExecuteRepository().save(entity);
}

我想查找与事件键匹配的StepDefintions。

我尝试按照JPA文档中的示例...

public class SomeClient {

  @Autowired
  private PersonRepository repository;

  public void doSomething() {
    List<Person> persons = repository.findByLastname("Matthews");
  }
}

但我的sdRepository抱怨它没有初始化。我在..ServiceImpl.aj中找到了getStepDefintionRepository()但是无法调用它。

那里有一个例子吗?

1 个答案:

答案 0 :(得分:0)

好的,我发现了我的错误......这是有效的。

@Autowired
private StepDefinitionRepository sdRepository;

/**
 * Overridden save method to intercept and process the dynamic steps before saving
 * 
 * @param entity
 * @return EventExecute
 */
@Transactional
public EventExecute save(EventExecute entity) {

    boolean keepGoing = true;
    String eventKey = entity.getEventKey();
    Set<NameValuePair> messageVariables = null;
    String eventArguments = entity.getEventArguments();
    List<NameValuePair> eventVariables = null;

    if (!eventArguments.isEmpty()){
        eventVariables = _ExtractEventVariables(eventArguments);
    }

    List<StepDefinition> stepDefinitions = sdRepository.findByEventKeyAllIgnoreCaseOrderBySequenceAsc(eventKey);

    for (Iterator<StepDefinition> iterator = stepDefinitions.iterator(); iterator.hasNext();) {