OneToMany方面的JoinColumn无法正常工作

时间:2017-05-17 07:18:33

标签: hibernate jpa hibernate-annotations

为什么我无法在/friends/userId/friendId/nickname方创建@JoinColumn?它抛出:

OneToMany

当我更改方向时 - 将2017-05-17 09:13:34.063 WARN 7724 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleMapper' defined in file [C:\MyProjects\myjnia\Myjnia_Inzynier\target\classes\com\carwash\mappers\RoleMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in com.carwash.MyjniaInzynierApplication: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available . //always the same but with every mapper interface . . 放在JoinColumn侧,它可以正常工作,但我希望从Wash表中引用Wash

Admin上课:

Admin

public class Admin { private Integer adminId; private User userId; private List<Wash> washId; @OneToMany(mappedBy = "washAdmin", fetch = FetchType.LAZY) @JoinColumn(name = "washId") public List<Wash> getWashId() { return washId; } 上课:

Wash

1 个答案:

答案 0 :(得分:0)

在这种情况下,你需要使你的关系双向,你有两个选择,要么你有单向关系,而joinColumn将在拥有实体中,否则你将具有单向。

检查此示例如何创建单向关系

  

http://www.codesenior.com/en/tutorial/Hibernate-Unidirectional-OneToMany-and-ManyToOne-Concepts

JoinColumn应该是非常严格的(在你的情况下没有收集的那个)并且mappedby应该是非严格的