请帮我找出问题。我是 spring hibernate 的初学者,在我的项目中使用 Spring 3 和 hibernate 4,我想在我的应用程序中使用 namedQuery。我创建了一个命名查询来使用连接从多个表中获取数据,但是我遇到了一些问题,如果我在这里做错了,请纠正我。Vode 低于 Entity 类:-
@Embeddable
@NamedQuery(
name = "findAllProduct",
query = "SELECT PVPOL.pincode,PO.description"
+" FROM product_vendor_payment_option_location PVPOL"
+" INNER JOIN PVPOL.Payement_Id PID"
+" INNER JOIN PVPOL.pincode PC"
+" INNER JOIN PVPOL.paymentOptions PO"
+" where PVPOL.id = :Payement_Id"
)
public class PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION extends Entity {
@Column(name="id")
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="id")
private Collection<Product_Catalog_Vendor> Payement_Id;
@Column(name="pincode_id")
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="PINCODE_ID")
private Collection<Pincodes> pincode;
@Column(name = "payment_options")
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="payment_options")
private Set<Payment_Options> paymentOptions;
//getters and setters here
}
这些是我要从中获取数据的表:-
CREATE TABLE PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION (
ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
Payment_Id INTEGER UNSIGNED NOT NULL ,
PINCODE_ID INTEGER UNSIGNED NOT NULL ,
PAYMENT_OPTIONS INTEGER UNSIGNED NOT NULL ,
PRIMARY KEY(ID,Payment_Id, PINCODE_ID) ,
INDEX PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION_FKIndex1(PAYMENT_OPTIONS),
INDEX PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION_FKIndex2(Payment_Id) ,
INDEX PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION_FKIndex3(PINCODE_ID),
FOREIGN KEY(PAYMENT_OPTIONS)
REFERENCES PAYEMENT_OPTIONS(PAYMENT_OPTIONS)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FOREIGN KEY(Payment_Id)
REFERENCES PRODUCT_CATALOG_VENDOR(Id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
FOREIGN KEY(PINCODE_ID)
REFERENCES PINCODES(PINCODE_ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE TABLE PAYEMENT_OPTIONS ( PAYMENT_OPTIONS INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, Description VARCHAR(500) NULL ,
PRIMARY KEY(PAYMENT_OPTIONS));
CREATE TABLE PRODUCT_CATALOG_VENDOR (
Id INTEGER UNSIGNED NOT NULL , Prefilled_Response_Id INTEGER UNSIGNED NULL ,
Product_Catalog_Id INTEGER UNSIGNED NOT NULL , User_Id INTEGER UNSIGNED NOT NULL ,
Aud_Create_Time TIMESTAMP NOT NULL , Aud_Update_Time TIMESTAMP NOT NULL ,
PRIMARY KEY(Id) ,INDEX PRODUCT_CATALOG_VENDOR_FKIndex1(Product_Catalog_Id) ,
INDEX PRODUCT_CATALOG_VENDOR_FKIndex2(User_Id) ,INDEX PRODUCT_CATALOG_VENDOR_FKIndex3(Prefilled_Response_Id), FOREIGN KEY(Product_Catalog_Id)
REFERENCES PRODUCT_CATALOG(Product_Catalog_Id)
ON DELETE CASCADE
ON UPDATE NO ACTION, FOREIGN KEY(User_Id) REFERENCES VENDOR(User_Id)
ON DELETE CASCADE ON UPDATE NO ACTION, FOREIGN KEY(Prefilled_Response_Id)
REFERENCES PREFILLED_RESPONSE(Prefilled_Response_Id) ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE TABLE PINCODES (
PINCODE_ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
PINCODE INTEGER UNSIGNED NOT NULL, Description INTEGER UNSIGNED NULL,
PRIMARY KEY(PINCODE_ID));
在 DAO 类中,我通过以下方式调用 namedQuery:-
Session session = sessionFactory.getCurrentSession();
Query query=(Query) session.getNamedQuery("findAllProduct");
当我在部署后运行时,日志中出现以下错误:-
10:27:36,139 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (MSC service thread 1-2) Root mapping to handler 'productController'
10:27:36,626 INFO [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-2) FrameworkServlet 'product': initialization completed in 3979 ms
10:27:36,633 INFO [org.jboss.web] (MSC service thread 1-2) registering web context: /usermanagement
10:27:36,636 INFO [org.jboss.as] (MSC service thread 1-4) JBoss AS 7.0.2.Final "Arc" started in 8346ms - Started 182 of 239 services (57 services are passive or on-demand)
10:27:36,670 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "usermanagement.war"
10:27:52,987 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/usermanagement].[product]] (http--127.0.0.1-8080-1) Servlet.service() for servlet product threw exception: org.hibernate.MappingException: Named query not known: findAllProduct
at org.hibernate.internal.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:154) [hibernate-core-4.1.10.Final.jar:]
at org.hibernate.internal.SessionImpl.getNamedQuery(SessionImpl.java:1343) [hibernate-core-4.1.10.Final.jar:]
at com.ecom.data.access.product.ProductDaoImpl.getAllProduct(ProductDaoImpl.java:36) [classes:]
at com.ecom.data.access.transaction.ProductServiceImpl.getAllProduct(ProductServiceImpl.java:30) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_43]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_43]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_43]
at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_43]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) [spring-aop-3.2.2.RELEASE.jar:]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) [spring-aop-3.2.2.RELEASE.jar:]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.2.2.RELEASE.jar:]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) [spring-tx-3.2.2.RELEASE.jar:]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) [spring-tx-3.2.2.RELEASE.jar:]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) [spring-tx-3.2.2.RELEASE.jar:]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.2.2.RELEASE.jar:]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) [spring-aop-3.2.2.RELEASE.jar:]
at com.sun.proxy.$Proxy35.getAllProduct(Unknown Source)
at com.ecom.data.access.controller.ProductController.listProducts(ProductController.java:24) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_43]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_43]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_43]
at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_43]
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) [spring-web-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) [spring-webmvc-3.2.2.RELEASE.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) [spring-webmvc-3.2.2.RELEASE.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_43]
期待一些建议...