需要使用Hibernate

时间:2017-04-01 10:21:30

标签: java hibernate

只想使用Hibernate作为ORM从java调用SQL服务器的存储过程。

存储过程有如此多的结果集,我将它保存在Java中作为DTO,并将每个作为列表放在一个DTO中作为JSON有效负载发送给前端集成。

但是我得到例外说法" org.hibernate.MappingException:未知实体:com.test.plans.dto.TemplatesDTO"

 public ItemDetailsDTO getItemDetails(int no) {
     Session session = getSession();
     Connection connection = null;
     List<ItemDetailsDTO> resultList  = new ArrayList<>();
     try {
            ResultSet rs = null;
            SessionImpl sessionImpl = (SessionImpl) session;
            connection = sessionImpl.connection();
            Query query = session.createSQLQuery("exec usp_GetItemDetails :no")
                         .addEntity(TemplatesDTO.class)
                         .setParameter("no", no);
            resultList = query.list();
     } catch (Exception e) {
            System.out.println("error");
            e.printStackTrace();
     }
     return resultList.get(0);
}

DTO:

import java.util.List;


public class ItemDetailsDTO {

    private List<TemplatesDTO> templates;


    public List<TemplatesDTO> gettemplates() {
        return templates;
    }
    public void settemplates(List<TemplatesDTO> templates) {
        this.templates = templates;
    }
}

请在下面找到完整的异常痕迹

  

org.hibernate.MappingException:未知实体:com.test.plans.dto.TemplatesDTO                   在org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:783)                   在org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:358)                   在org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:411)                   在org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:378)                   在org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:180)                   在org.hibernate.loader.custom.sql.SQLCustomQuery。(SQLCustomQuery.java:71)                   at org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl.createQueryPlan(NativeQueryInterpreterStandardImpl.java:70)                   在org.hibernate.engine.query.spi.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:210)                   at org.hibernate.internal.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:306)                   at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322)                   在org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125)                   at nbcu.compass.contingencyplans.dao.impl.ContDAOImpl.getItemDetails(ContingencyDAOImpl.java:503)                   at nbcu.compass.contingencyplans.dao.impl.ContDAOImpl $$ FastClassBySpringCGLIB $$ c2b97106.invoke()                   在org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)                   在org.springframework.aop.framework.CglibAopProxy $ CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)                   在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)                   at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)                   在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)                   在org.springframework.aop.framework.CglibAopProxy $ DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)                   在com.test.plans.dao.impl.ContDAOImpl $$ EnhancerBySpringCGLIB $$ a1741e1f.getItemDetails()                   at com.test.plans.service.impl.ContPlanServiceImpl.getConditionScheduleItemDetails(ContingencyPlanServiceImpl.java:316)                   at test.plans.plans.rest.impl.PlanResourceImpl.getItemDetails(PlanResourceImpl.java:87)                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                   at java.lang.reflect.Method.invoke(Method.java:498)                   在org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)                   在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)                   在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)                   在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)                   在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)                   在org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)                   在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)

0 个答案:

没有答案