Aggressive
Aggressive

Reputation: 93

Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field:

I'm trying to save the fields in a form using Spring MVC and Hibernate. But here i'm getting some exceptions as below.The form contains two elements with type file.. i can't find any mistake in the code. Can anyone please help me to get rid of this exception. Thanks in advance....

Here is my Controller:

@Controller
@RequestMapping(value = "ecom")
public class MerchantController {
   @Autowired
   MerchantService merchantService;

    @RequestMapping(value = "/saveMe", method = { RequestMethod.POST, RequestMethod.GET })
    public ModelAndView saveMe(ModelMap model, HttpServletRequest req) throws FileUploadException  {  
       System.out.println("inside controller");
        String status = merchantService.saveAll(req);
        model.put("status",status);  
       return new ModelAndView("merchantRegistration",model);
    }
}

This is my ServiceImpl:

@Service("merService")
@Transactional
public class MerchantServiceImpl implements MerchantService {
@Autowired
MerchantDao merchantDao;
    @Override
    public String saveAll(HttpServletRequest req){
        System.out.println("inside serv");
        boolean isMultipart = ServletFileUpload.isMultipartContent(req);
        boolean boolStatus=false;
        byte[] bytes = null;
        byte[] bytesTwo = null;
        Merchant merchant = new Merchant();
        if(isMultipart) {
            try {
                FileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);
                List<FileItem> items = upload.parseRequest(req);
                Iterator iter = items.iterator();
                while (iter.hasNext()) {
                    FileItem item = (FileItem) iter.next();
                    String fieldName = item.getFieldName();
                    if (item.isFormField()) {
                        if (fieldName.equalsIgnoreCase("merchant-name")) {
                            merchant.setMerchantName(item.getString());
                        }else if (fieldName.equalsIgnoreCase("industry")) {
                            Industry industry = new Industry();
                            industry = merchantDao.getIndustry(Integer.parseInt(item.getString())); 
                            merchant.setIndustry(industry);
                        } else if (fieldName.equalsIgnoreCase("cmpny-reg-no")) {
                            merchant.setMerchantNo(item.getString());
                        } else if (fieldName.equalsIgnoreCase("zakka-no")) {
                            merchant.setMerchantZakka(item.getString());
                        } else if (fieldName.equalsIgnoreCase("bank-id")) {
                            Bank bank = new Bank();
                            bank = merchantDao.getBank(Integer.parseInt(item.getString()));
                            merchant.setBankId(bank);
                        } else if (fieldName.equalsIgnoreCase("bank-acc-no")) {
                            merchant.setMerchantAccount(item.getString());
                        } else if (fieldName.equalsIgnoreCase("bank-code")) {
                            merchant.setMerchantIfsc(item.getString());
                        } else if (fieldName.equalsIgnoreCase("service")) {
                            Services services = new Services();
                            services = merchantDao.getService(Integer.parseInt(item.getString()));
                            merchant.setServiceId(services);
                        } else if (fieldName.equalsIgnoreCase("fb")) {
                            merchant.setSocialNtwrk1(item.getString());
                        } else if (fieldName.equalsIgnoreCase("gplus")) {
                            merchant.setSocialNtwrk2(item.getString());
                        } else if (fieldName.equalsIgnoreCase("twitter")) {
                            merchant.setSocialNtwrk3(item.getString());
                        } else if (fieldName.equalsIgnoreCase("flickr")) {
                            merchant.setSocialNtwrk4(item.getString());
                        }
                        merchant.setCreated(new Timestamp(new Date().getTime()));
                    } else {
                        try {
                            if (fieldName.equalsIgnoreCase("logo")) {
                                bytes = IOUtils.toByteArray(item.getInputStream());
                                String fileName1 = item.getName();
                                int indexOfFile1 = 0;
                                if (fileName1.contains("\\")) {
                                    indexOfFile1 = fileName1.lastIndexOf("\\");
                                    fileName1 = fileName1.substring(indexOfFile1 + 1);
                                    //msg = msg + "With file "+fileName1;
                                }
                                merchant.setMerchantLogo(bytes);
                            } else if (fieldName.equalsIgnoreCase("banner")) {
                                bytesTwo = IOUtils.toByteArray(item.getInputStream());
                                String fileName2 = item.getName();
                                int indexOfFile2 = 0;
                                if (fileName2.contains("\\")) {
                                    indexOfFile2 = fileName2.lastIndexOf("\\");
                                    fileName2 = fileName2.substring(indexOfFile2 + 1);
                                    //msg = msg + ", "+fileName2;
                                }
                                merchant.setMerchantBanner(bytesTwo);
                            }

                        } catch (IOException ex) {
                            //Logger.getLogger(ExceptionAndInvestigation.class.getName()).log(Level.SEVERE, null, ex);
                            // logger.error(ex);
                        }
                    }
                }
            } catch (FileUploadException ex) {
                Logger.getLogger(MerchantServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            }

          boolStatus= merchantDao.saveInfo(merchant);
            }

         JSONObject jsonObj = new JSONObject();
        if(boolStatus){
            jsonObj.put("message","Saved Successfully" );
            jsonObj.put("status","success");
        }else{
            jsonObj.put("message","Save Failed" );
            jsonObj.put("status","fail");
        }
        return jsonObj.toString();
    }
}

This is the DaoImpl:

@Repository
public class MerchantDaoImpl implements MerchantDao {
    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public boolean saveInfo(Merchant merchant){
        boolean flag = false;
        try {
            System.out.println("Inside dao");
            Session session = sessionFactory.getCurrentSession();
            session.save(merchant);
            flag = true;
        } catch (Exception e) {
            System.out.println("Exception in saving ..."+e.getMessage());
        }
        return flag;
    }

    @Override
    public Industry getIndustry(int intIndustryId){
        Session session = sessionFactory.getCurrentSession();
        Industry industry = (Industry) session.get(Industry.class, intIndustryId);
        return(Industry) industry;
    }

    @Override
     public Bank getBank(int intBankId){
        Session session = sessionFactory.getCurrentSession();
        Bank bank = (Bank) session.get(Bank.class, intBankId);
        return(Bank) bank;
     }

     public Services getService(int intServiceId){
        Session session = sessionFactory.getCurrentSession();
        Services service = (Services) session.get(Services.class, intServiceId);
        return(Services) service;
     }

I'm getting the exception as below:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merchantController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ecommerce.service.MerchantService com.ecommerce.controller.MerchantController.merchantService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ecommerce.dao.MerchantDao com.ecommerce.service.MerchantServiceImpl.merchantDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merchantDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.ecommerce.dao.MerchantDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1291)
    at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:390)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2442)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2431)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ecommerce.service.MerchantService com.ecommerce.controller.MerchantController.merchantService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ecommerce.dao.MerchantDao com.ecommerce.service.MerchantServiceImpl.merchantDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merchantDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.ecommerce.dao.MerchantDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    ... 44 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ecommerce.dao.MerchantDao com.ecommerce.service.MerchantServiceImpl.merchantDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merchantDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.ecommerce.dao.MerchantDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    ... 46 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ecommerce.dao.MerchantDao com.ecommerce.service.MerchantServiceImpl.merchantDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merchantDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.ecommerce.dao.MerchantDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    ... 57 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'merchantDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.ecommerce.dao.MerchantDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    ... 59 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.ecommerce.dao.MerchantDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    ... 70 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    ... 72 more
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses
    at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:768)
    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:728)
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
    at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1695)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1424)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
    ... 82 more

Here is my entity:

@Entity
@Table(name="ECOM_TRANSACTIONS")
public class Transactions implements Serializable {
     @Id 
     @Column(name="TRANSACTIONID", unique=true, nullable=false)
     private String transactionid;
     @ManyToOne(fetch=FetchType.LAZY)
     @JoinColumn(name="SERVICEID", nullable=false)
     private Services services;
     @ManyToOne(fetch=FetchType.LAZY)
     @JoinColumn(name="MERCHANTID")
     private Merchant merchant;
     @Column(name="TRANSACTIONMERCHANTID", nullable=false)
     private String transactionmerchantid;
     @Column(name="FNAME", length=100)
     private String fname;
     @Column(name="LNAME", length=100)
     private String lname;
     @Column(name="EMAIL")
     private String email;
     @Column(name="AMOUNT", precision=126, scale=0)
     private Double amount;
     @Column(name="STATUS", length=20)
     private String status;
     @Column(name="IPADDRESS", length=17)
     private String ipaddress;
     @Column(name="CREATED")
     @Temporal(javax.persistence.TemporalType.TIMESTAMP)
     private Date created;
     @Column(name="DESCRIPTION")
     private String description;

   getters and setters

Services Entity:

public class Services implements Serializable {

    @Id 
    @Column(name="SERVICEID", unique=true, nullable=false, precision=22, scale=0)
    private int serviceId;
    @Column(name="SERVICETYPE", nullable=false)
    private String serviceType;
    @Column(name="REGISTERCHARGE", precision=17, scale=0)
    private int registerCharge;
    @Column(name="MONTHLYCHARGE", precision=17, scale=0)
    private int monthlyCharge;
    @Column(name="TRANSFFERCHARGE", precision=17, scale=0)
    private int transferCharge;
    @OneToMany(fetch=FetchType.LAZY, mappedBy="serviceId")
    private Set<Transactions> transactionses = new HashSet<Transactions>(0);
    @OneToMany(fetch=FetchType.LAZY, mappedBy="serviceId")
    private Set<Merchant> merchants = new HashSet<Merchant>(0);

getters and setters

Upvotes: 1

Views: 5223

Answers (2)

user180100
user180100

Reputation:

This error message:

mappedBy reference an unknown target entity property: 
   com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses

tells you that in Services you did use an hibernate annotation like @OneToMany and did specify for the annotation mappedBy attribute serviceId but as seen in the code you posted for Transactions, there is no serviceId attribute.

So you have to replace in Services:

@OneToMany(fetch=FetchType.LAZY, mappedBy="serviceId")
private Set<Transactions> transactionses = new HashSet<Transactions>(0);

by:

@OneToMany(mappedBy = "services") // use the name of the field
private Set<Transactions> transactionses = new HashSet<Transactions>(0);

Upvotes: 1

m.aibin
m.aibin

Reputation: 3603

It will be a problem with a model. You need to set the mappedBy attribute of the @OneToMany/@ManyToOne annotation properly in entity classes -> you didn't provide entity classes, but there is for sure a problem with com.ecommerce.model.Transactions.serviceId in com.ecommerce.model.Services.transactionses

Upvotes: 0

Related Questions