0

我有以下 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()));
    }
}
4

1 回答 1

0

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

于 2012-07-18T15:38:51.670 回答