注入自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:

时间:2015-12-03 06:27:35

标签: java hibernate spring-mvc

我尝试使用Spring MVC和Hibernate保存表单中的字段。但是在这里我得到了一些例外,如下所示。表单包含两个带有类型文件的元素。我无法在代码中找到任何错误。任何人都可以帮我摆脱这个例外。提前谢谢....

这是我的控制器:

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

这是我的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();
    }
}

这是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;
     }

我得到如下例外:

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

这是我的实体:

@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

服务实体:

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

getter and setters

2 个答案:

答案 0 :(得分:1)

此错误消息:

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

告诉您,在Services中您确实使用了像@OneToMany这样的hibernate注释,并确实为注释mappedBy属性serviceId指定了但是如您发布的代码中所示Transactions,没有serviceId属性。

所以你必须替换Services

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

由:

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

答案 1 :(得分:0)

这将是模型的问题。您需要在实体类中正确设置@OneToMany/@ManyToOne注释的mappedBy属性 - &gt;您没有提供实体类,但com.ecommerce.model.Transactions.serviceId

中的com.ecommerce.model.Services.transactionses确实存在问题