JPA / Hibernate,Spring Roo:可以将Repository和ActiveRecord共存吗?

时间:2012-07-16 15:12:57

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

我有以下Spring MVC控制器,它同时使用存储库和活动记录。我系统地得到以下例外:

Caused by: javax.persistence.EntityNotFoundException: Unable to find trc.suivi.domain.Destinataire with id 892
    at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:137)
    at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:233)
    at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
    at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
    at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
    at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
    at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
    at org.hibernate.type.EntityType.resolve(EntityType.java:438)
    at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
    at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982)
    at org.hibernate.loader.Loader.doQuery(Loader.java:857)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2542)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
    ... 78 more

请注意,该行确实存在于数据库!!

这是我的控制器代码:

@RequestMapping("/plis")
@Controller
@RooWebScaffold(path = "plis", formBackingObject = Pli.class)
@RooWebFinder
public class PliController {

    @Autowired
    private PliRepository pliRepository;

    @RequestMapping(params = { "find=ByMultiField", "form" }, method = RequestMethod.GET)
    public String findPlisByMultiFieldForm(Model uiModel) {
        populateMultiFieldForm(uiModel);
        return "plis/findPlisByMultiField";
    }

    @RequestMapping(params = "find=ByMultiField", method = RequestMethod.GET)
    public String findPlisByMultiField(@RequestParam("identifiant") String identifiant, Model uiModel) {
        uiModel.addAttribute("plis", pliRepository.findPlisByMultiFieldQuery(identifiant, null, false, false, null, false, null, null).getResultList());//REPOSITORY USAGE
        return "plis/list";
    }

    void populateMultiFieldForm(Model uiModel) {
        uiModel.addAttribute("pli_datereception_date_format", DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
        uiModel.addAttribute("conteneurnums", ConteneurNum.findAllConteneurNums());//ACTIVE RECORD USAGE
        uiModel.addAttribute("statutplis", Arrays.asList(StatutPli.values()));
    }
}

1 个答案:

答案 0 :(得分:0)

简短回答是肯定的:存储库和ActiveRecord可以共存。我的问题可能是由于某些版本问题。