解决:DuplicateMappingException: Table [xx] contains physical column name referred to by multiple ... .
生活随笔
收集整理的這篇文章主要介紹了
解决:DuplicateMappingException: Table [xx] contains physical column name referred to by multiple ... .
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
報錯如題:
Caused by: org.hibernate.DuplicateMappingException: Table [xxx] contains physical column name [comment] referred to by multiple physical column names: [comment], [auditComment]at org.hibernate.boot.internal.InFlightMetadataCollectorImpl$TableColumnNameBinding.bindPhysicalToLogical(InFlightMetadataCollectorImpl.java:922)at org.hibernate.boot.internal.InFlightMetadataCollectorImpl$TableColumnNameBinding.addBinding(InFlightMetadataCollectorImpl.java:891)at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addColumnNameBinding(InFlightMetadataCollectorImpl.java:961)at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.addColumnNameBinding(InFlightMetadataCollectorImpl.java:942)at ... ...?
情況1. 項目用的 spring-data-jpa 。
原本對于表和本類的每個字段都有給注解 @Colum 來對應,其實不用給也可以。把這些注解注釋掉工程就可以正常啟動了。
如下:
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.map.annotate.JsonSerialize;import javax.persistence.*; import java.io.Serializable; import java.util.Date;/*** 解凍申請*/ @Entity(name = "unfreeze") @Table(name = "unfreeze_apply") @JsonIgnoreProperties(ignoreUnknown = true) public class UnfreezeApply implements Serializable {private static final long serialVersionUID = -1826761763082698565L;@Id@GeneratedValue(strategy = GenerationType.AUTO)private Integer id;// @Column(name = "employee_no", nullable = false)private String employeeNo;@Transientprivate String employeeName; //員工名稱@ManyToOne(fetch = FetchType.EAGER)@JsonIgnore // @JoinColumn(name="employee_no", referencedColumnName="usernumber", insertable=false, updatable=false)private User employee;// @Column(name = "reason", nullable = false)private String reason;}啟動成功:
?
情況2. (網上的其它情況)
?
當有一個物理表映射兩個或多個邏輯表名稱時,會發生此異常。如?因為那里有多個@JoinColumns使用相同的列名(user_id)
為每個JoinColumns(在注釋中的name參數中定義)設置一個不同的名稱:
@OneToOne @JoinColumn(name = "local_user_id") public User getUser() {return user; }@OneToOne @JoinColumns({@JoinColumn(name = "userId", referencedColumnName = "userId"),@JoinColumn(name = "providerId", referencedColumnName = "providerId"),@JoinColumn(name = "providerUserId", referencedColumnName = "providerUserId")} ) public UserConnection getUserConnection() {return userConnection; }?
參考:http://mussatto.github.io/java/hibernate/error/fix/mapping/2016/11/14/hibernate-error-multiple-physical-columns.html
?
?
?
總結
以上是生活随笔為你收集整理的解决:DuplicateMappingException: Table [xx] contains physical column name referred to by multiple ... .的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2020.3
- 下一篇: docker-compose 使用小例