我在Maven的应用程序中使用Spring 3和Hibernate 4。我得到一些问题是由于Hibernate Mapping所以我正在努力。但现在我陷入困境,无法找到解决方案。如果我做错了,请纠正我。我的实体类是我编写NamedQuery的地方: -
@Entity
@NamedQuery(
name = "findAllProduct",
query = "from PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION pvpo"
+" INNER JOIN pvpo.pcvId pcv"
+" INNER JOIN pcv.productCatalogId pc"
+" INNER JOIN pc.productCatalogId id"
+" INNER JOIN pvpo.pincode pin"
+" where id = :id"
)
public class PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION extends baseEntity.Entity {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Column(name="Payment_Id")
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="id")
private Set<Product_Catalog_Vendor> pcvId;
@Column(name="pincode_id")
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="pincode_id")
private Set<Pincodes> pincode;
@Column(name = "PAYMENT_OPTIONS")
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="paymentOptions")
private Set<Payment_Options> paymentOptions;
//setter getter
}
我的Payment_Options类是: -
@Entity
@Table(name="payement_options")
public class Payment_Options extends baseEntity.Entity {
@Id
@JoinColumn(name="PAYMENT_OPTIONS")
private int paymentOptions;
@Column(name="Description")
private String description;
//Setter Getter
}
PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION和PAYMENT_OPTIONS数据库中的表: -
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));
我在部署时遇到错误。在下面为我提供一些解决方案。谢谢!
18:12:26,614 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6e677ea2: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,productController,usermanagementHibernateProperties,jspViewResolver,usermanagementSessionFactory,usermanagementDataSource,city,state,country,pincodes,notification,notification_types,transactions,address,user_master,notification_channels,notification_time,prefilled_response,payment_options,catagory,vendor,requester,requirement_type,discount_offer_type,discount_offers,requirements,product_catalog,product_catalog_vendor,product_vendor_payment_option_location,baseDaoImpl,productDAO,productService,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
18:12:26,624 SEVERE [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-3) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ecom.data.access.transaction.ProductService com.ecom.data.access.controller.ProductController.productService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ecom.data.access.product.ProductDAO com.ecom.data.access.transaction.ProductServiceImpl.productDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.ecom.data.access.product.ProductDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usermanagementSessionFactory' defined in class path resource [applicationContext-usermanagement-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing column: paymentOptions in 2402.payement_options
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.2.RELEASE.jar:]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) [spring-webmvc-3.2.2.RELEASE.jar:]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-3.2.2.RELEASE.jar:]
at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [:1.6.0_43]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [:1.6.0_43]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_43]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ecom.data.access.transaction.ProductService com.ecom.data.access.controller.ProductController.productService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ecom.data.access.product.ProductDAO com.ecom.data.access.transaction.ProductServiceImpl.productDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.ecom.data.access.product.ProductDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usermanagementSessionFactory' defined in class path resource [applicationContext-usermanagement-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing column: paymentOptions in 2402.payement_options
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) [spring-beans-3.2.2.RELEASE.jar:]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) [spring-beans-3.2.2.RELEASE.jar:]
... 27 more
答案 0 :(得分:1)
您需要创建数据库表,使它们与Entitymapping匹配。
第一个问题是,Payment_Options
表中的id列名为PAYMENT_OPTIONS
。但是,您在Payment_Options
课程中的字段名为paymentOptions
(并且没有@Column
注释) - 这不匹配!
所以在字段中添加@Column(name="PAYMENT_OPTIONS")
:
@Id
@Column(name="PAYMENT_OPTIONS")
@JoinColumn(name="PAYMENT_OPTIONS") //I have no idea what you want to do with this annotation
private int paymentOptions;
但真正的问题是你对Payment_Options
和PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION
之间关系的映射非常奇怪。
首先,我认为你把它们命名为错误。 PaymentOption
没有s
。
我建议:
public class PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION
...
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER, mappedBy="pvpol")
private Set<Payment_Options> paymentOptions;
...
}
public class PaymentOption ...
...
@ManyToOne
PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION pvpol;
...
}
答案 1 :(得分:0)
我有类似的问题。 在我的情况下,我必须删除属性:
spring.jpa.hibernate.ddl-自动=验证
来自我的 application.properties 文件