'DuplicateMappingException represented by different logical column names
I'm using OneToMany mapping for two classes MasavNew and 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;
}
and then in running I receive next Exception:
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)
How could I solve the problem ?
Solution 1:[1]
Remove
@Id
@Column(name = "[Arg.CH.F.Key]", nullable = false)
private int argCHFKey;
As you can get the key from your msv object.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Draken |