0

I am using Spring 3 and Hibernate 4 in my Application with Maven. I am getting some issues which are due to Hibernate Mapping so i am working on it. But now i am stuck and unable to find the solution. please correct me if i am doing something wrong. My entity class is where i have written my 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
        }

My Payment_Options class is:-

@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 and PAYMENT_OPTIONS Table in database:-

    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));

I am getting below error at deployement time. Provide me some solution on below. Thanks!

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

2 Answers 2

1

You need to create the database tables so that they match the Entitymapping.

The first problem is, that the id column in your Payment_Options table is named PAYMENT_OPTIONS. But your field in class Payment_Options is named paymentOptions (and has no @Column Annotation) - This does not match!

So add @Column(name="PAYMENT_OPTIONS") to the field:

@Id
@Column(name="PAYMENT_OPTIONS")
@JoinColumn(name="PAYMENT_OPTIONS") //I have no idea what you want to do with this annotation
private int paymentOptions;

But the real problem is that your mapping of the relation between Payment_Options and PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION is very strange.

First of all I think you named them wrong. It is PaymentOption without s.

I recommend:

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;
   ...
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your revert.you are right with your suggesion but i dont want to create a new property in my any entity class or DB table. I have already created Tables in database. pls refer edited question for table PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION where i have 3 foreign keys and one composite key. i am refering Payment_Options class's foreign key using joincolumn, similarly i am refering keys to pincodes and Product_Catalog_Vendor keys which is working fine,so why i am getting the issue with Payment_Options class.So tell me what is the issue with this mapping ,m i mising somthing?
the problem is not the PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION table, the problem is the Payment_Option table. But you do not have posted its structure!
See my extended answer.
0

I had similar problem. In my case I had to remove property:

spring.jpa.hibernate.ddl-auto=validate

from my application.properties file

1 Comment

This just hides the problem by turning off validations, this does not solve the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.