Quote:
table A: (PK: id)
ID NAME OTHER
1 a1 ...
2 a2 ...
3 a3 ...
p.s.:
`NAME` is unique. It's logical primary key on table A. And `ID` is true pk.
Quote:
table B: (PK: id)
ID A_NAME GROUP OTHER
1 a1 g1 ...
2 a1 g2 ...
3 a2 g2 ...
4 a4 g3 ...
p.s.:
`A_NAME` and `GROUP` is together unique. These are logical composite primary key. `ID` is true pk.
Table B have not foreign key about A. But logically, table B.A_NAME = A.NAME(like B.A_ID = A.ID, but we don't design A_ID for table B).
I want to query 'SELECT * FROM A, B WHERE B.A_NAME = A.NAME'. what should I design this two table's Entities?
(1)I do it like the blow codes. but it throw exception:
Code:
@Entity
@Table(name="A")
public class A {
@ID
private Integer id;
@OneToMany(mappedBy="b")
private String name;
}
Code:
@Entity
@Table(name="B")
public class B {
@ID
private Integer id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="A_NAME", referencedColumnName="NAME", nullable=false),
private String a_name;
}
Exceptions:
Caused by: org.hibernate.MappingException: Unable to find column with logical name: GroupNo in org.hibernate.mapping.Table(DmGoodsStore) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:583)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:258)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1598)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1521)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1422)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
... 29 more