DuplicateMappingException由不同的逻辑列名称表示

时间:2014-07-29 15:15:56

标签: java hibernate jpa

我使用OneToMany映射两个类MasavNew和MasavRow:

@Entity
@Table(name = "ArgoCHFileHdr")
public class MasavNew  {


@OneToMany(fetch = FetchType.LAZY, mappedBy = "msv",cascade = CascadeType.ALL)
@ElementCollection(targetClass=MasavRow.class)
private List<MasavRow> rows;

@Id
@Column(name = "[Arg.CH.F.Key]", nullable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected Integer argCHFKey;

}


@Entity
@Table(name = "ArgoCHFileRow")
@DynamicUpdate
public class MasavRow extends IModel {


@ManyToOne(fetch = FetchType.LAZY,optional=true)
@JoinColumn(name="[Arg.CH.F.Key]")
private MasavNew msv;


@Id
@Column(name = "[Arg.CH.F.Key]", nullable = false)
private int argCHFKey;


@Id
@Column(name = "[Arg.CH.L.MNB]", nullable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer argCHLMNB;


@Column(name = "[Erp.Clnt]", nullable = true)
private String erpClnt;


}

然后在跑步中我收到下一个例外:

Caused by: org.hibernate.DuplicateMappingException:  Table [ArgoCHFileRow] contains physical column name [`Arg.CH.F.Key`] represented by different logical column names: [`Arg.CH.F.Key`], [Arg.CH.F.Key]
    at org.hibernate.cfg.Configuration$MappingsImpl$TableColumnNameBinding.bindPhysicalToLogical(Configuration.java:3185)
    at org.hibernate.cfg.Configuration$MappingsImpl$TableColumnNameBinding.addBinding(Configuration.java:3158)
    at org.hibernate.cfg.Configuration$MappingsImpl.addColumnBinding(Configuration.java:3202)
    at org.hibernate.cfg.Ejb3JoinColumn.addColumnBinding(Ejb3JoinColumn.java:532)
    at org.hibernate.cfg.Ejb3Column.linkWithValue(Ejb3Column.java:364)
    at org.hibernate.cfg.annotations.TableBinder.linkJoinColumnWithValueOverridingNameIfImplicit(TableBinder.java:523)
    at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:457)
    at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:117)
    at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1596)
    at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1519)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1420)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)

我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:0)

删除

@Id
@Column(name = "[Arg.CH.F.Key]", nullable = false)
private int argCHFKey;

您可以从msv对象中获取密钥。