0

I have some difficulties with a JPA scenario that i'm unable to resolve. I search on Stackoverflow a similar case, but i didn't found.

I only found this topic, but it's not exactly my case...

If it already exists, I'm sorry.

Here's my case :

I have two tables :

A :

id label ref_name
1 ARK Bruce
2 HAM Alfred

B :

id name lastname
1 Bruce Wayne
2 Alfred Pennyworth
3 Bruce Banner

Table B represents a list of persons. Table A has a label name, and a column to list all persons from Table B that has a particular name.

In Java I have these 2 entities :

public class B {

   private Integer id;

   private String name;

   private String lastname;
}
public class A {

   private Integer id;

   private String label;

   @ManyToMany
   @JoinColumn(name="ref_name", referencedColumnName="name")
   private List<B> persons;
}

So, I've tried this code, and i have the following error message :

ERROR: relation "A_persons" does not exist

I can't figure what's wrong with this ...

Thank you for your help !

Apodeus
  • 105
  • 2
  • 7

1 Answers1

0

By observing your use of many-to-many mapping, I am guessing you are trying to do many-to-many mapping without the use of a "junction-table". I found this Stackoverflow answer showing how this can be done. What do you think? https://stackoverflow.com/a/25018992

public class A {
    private Integer id;
    private String label;
    @OneToMany
    @JoinColumn(name="ref_name",
        referencedColumnName="name")
    private List<B> persons;
}
Andrew NS Yeow
  • 341
  • 2
  • 8
  • Hello, I have the following issue with this : org.hibernate.MappingException: Unable to find column with logical name. – Apodeus Jun 07 '21 at 13:29
  • @Apodeus, are you able to provide the fuller sentence of your error? Like `Unable to find column with logical name: zzz in org.hibernate.mapping.Table(yyy) and its related supertables and secondary tables`, the values `zzz` and `yyy`? – Andrew NS Yeow Jun 07 '21 at 15:33