First of all, this is a legacy DB and the schema cannot be changed. Now imagine I've the following tables:
----------- -----------
| table A | | table B |
----------- -----------
| id_A |----->| id_B |
| col_A | | col_B |
----------- -----------
Table A is the master and Table B is the detail. Both id_A and id_B are strings BUT id_B = id_A + 4 characters.
For instance, if id_A = "0000000123" then there are multiple id_B like the following ones "00000001230001","00000001230002", "00000001230003", ... yes, I know, that should have been another column. As I said this is a legacy DB and I found it that way.
I'm using Spring Data JPA, JPA2 and Hibernate. And what I need is to define the entities:
@Entity
@Table(name="A")
public class A {
@Column(name = "id_A", length = 10, unique = true, nullable = false)
private String idA;
@Column(name = "col_A")
private String colA;
@OneToMany <-- WHAT MORE GOES HERE TO REFERENCE JUST THE SUBSTRING OF THE DETAIL id_B?
private List<B> detail;
}
@Entity
@Table(name="B")
public class B {
@Column(name = "id_B", length = 14, unique = true, nullable = false)
private String idB;
@Column(name = "col_B")
private String colB;
}
I don't know how to reference that what I need is that substr(id_b, 1, 10) = id_A
How can I do that?