一对多端的加入列不起作用



为什么我不能OneToMany端创建@JoinColumn?它抛出:

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:MyProjectsmyjniaMyjnia_InzyniertargetclassescomcarwashmappersRoleMapper.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侧,它可以工作,但我想从表中引用Admin Wash

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类:

public class Wash {
    private Integer washId;
    private String name;
    private WashLocation washLocation;
    private List<Worker> washWorker;
    private List<Reservation> washReservation;
    private List<WashWashType> washTypes;
    private Admin washAdmin;
    @ManyToOne()
    @JsonIgnore
    public Admin getWashAdmin() {
        return washAdmin;
    }
    public void setWashAdmin(Admin washAdmin) {
        this.washAdmin = washAdmin;
    }

在这种情况下,您需要使关系是双向的,您有两种选择,要么您有单向关系并且 joinColumn 将位于拥有实体中,要么您将具有单向关系。

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

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

JoinColumn 应该在拥有实体中

(在您的情况下没有集合的实体(,并且 mappedby 应该在 none owningentity 中

相关内容

  • 没有找到相关文章

最新更新