2016-09-30 3 views
0

Карта таблицы пользователя в UserProfilePersonalInfo таблицы для обновления данныхКак сопоставить одно POJO с другим POJO в Java?

В карте пользователя POJO

@OneToOne(mappedBy = "users",cascade = CascadeType.ALL) 
private UserProfilePersonalInfo userProfilePersonalInfo; 

В UserProfilePersonalInfo POJO

@OneToOne 
@JoinColumn(name = "user_id") 
private User user; 

В конфигурации Hibernate

@Bean 
public LocalSessionFactoryBean sessionFactory() { 
    LocalSessionFactoryBean sessionFactory = new 
    LocalSessionFactoryBean(); 
    sessionFactory.setDataSource(dataSource()); 
    sessionFactory.setPackagesToScan(new String[] { "com.a2z.model" }); 
    sessionFactory.setHibernateProperties(hibernateProperties()); 
    return sessionFactory; 
} 
private Properties hibernateProperties() { 
    Properties properties = new Properties(); 
    properties.put("hibernate.dialect", 
    environment.getRequiredProperty("hibernate.dialect")); 
    properties.put("hibernate.show_sql", 
    environment.getRequiredProperty("hibernate.show_sql")); 
    properties.put("hibernate.format_sql", 
    environment.getRequiredProperty("hibernate.format_sql")); 
    return properties;   
} 

Я облицовочные ошибка на консоли

WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'usersService': Error creating bean with name 'usersService': Unsatisfied dependency expressed through field 'userdao': Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersService': Unsatisfied dependency expressed through field 'userdao': Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users 
Sep 30, 2016 7:32:38 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
SEVERE: Context initialization failed 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'usersService': Error creating bean with name 'usersService': Unsatisfied dependency expressed through field 'userdao': Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersService': Unsatisfied dependency expressed through field 'userdao': Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersDao': Unsatisfied dependency expressed through field 'sessionFactory': Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/a2z/configuration/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown mappedBy in: com.a2z.model.User.userProfilePersonalInfo, referenced property unknown: com.a2z.model.UserProfilePersonalInfo.users 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4718) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

ответ

0
mappedBy = "user" 

Вот имя ява поле, а не имя SGBD поле. Подсказки: используйте имя поля sgbd, где слово Column отображается в @annotation

Смежные вопросы