简体   繁体   English

无法建立Hibernate SessionFactory插入更新为false

[英]Unable to build Hibernate SessionFactory insert update false

Table Client Name="clients" 表Client Name =“ clients”

@OneToMany(mappedBy="clientObj", fetch=FetchType.LAZY)
private List<BookedRoom> bookedRooms;

And table Booked Room 和桌子订的房间

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(unique=true, nullable=false)
private BigInteger id;

@Column(name="accommodation")
private BigInteger accommodation;

@Column(name="account")
private BigInteger account;

@Column(length=40)
private String clients;

@Column(name="clients_id", length=40)
private String clientsId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="clients", nullable=false)
@JsonBackReference 
private Client clientObj;

@Column(name="rooms_no")
private byte roomsNo;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="room", nullable=false)
@JsonBackReference 
private AccommodationRoom accommodationRoom;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="bed_preference")
@JsonBackReference 
private BedPreference bedPreferenceBean;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="booking", nullable=false)
@JsonBackReference 
private Booking bookingBean;

And error: 错误:

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: ba.go2balkan.pojo.BookedRoom column: clients (should be mapped with insert="false" update="false") [java] at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:709) [java] at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:731) [java] at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:753) [java] at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:506) [java] at org.hibernate.mapping.RootClass.validate(RootClass.java:270) [java] at org.hibernate.cfg.Configuration.validate(Configuration.java:1358) [java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849) [java] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) [java] ... 34 more 由以下原因引起:org.hibernate.MappingException:实体的映射中重复的列:ba.go2balkan.pojo.BookedRoom列:客户端(应与org.hibernate上的insert =“ false” update =“ false”映射)[java]。 org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:731)上的mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:709)[java]在org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java: 753)[java]在org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:506)[java]在org.hibernate.mapping.RootClass.validate(RootClass.java:270)[java]在org.hibernate。 cfg.Configuration.validate(Configuration.java:1358)[java]在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)[java]在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform (EntityManagerFactoryBuilderImpl.java:850)[java] ...另外34个

And don't tell me to insert (insertable="false", updateble="false"). 并且不要告诉我要插入(insertable =“ false”,updateble =“ false”)。 Because when I insert that than I can not read data from database or anything else. 因为当我插入它时,我无法从数据库或其他任何东西读取数据。 That's not solution. 那不是解决方案。

you have 你有

@Column(length=40)
private String clients;

and

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="clients", nullable=false)
@JsonBackReference 
private Client clientObj;

that are trying to map the same db column (if you don't specify column name then hibernate will use field name for column mapping)... 试图映射同一数据库列(如果您未指定列名,则休眠将使用字段名进行列映射)...

Either give a different name to the first if it's actually another column, use insertable=false, updatable= false on the non association mapping String clients or remove that meaningless field altogether 如果实际上是另一列,请给第一个起一个不同的名称,在非关联映射String clients上使用insertable=false, updatable= false或完全删除无意义的字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM