前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。
报错如题:
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