I'm using JPA and I'm having problems retrieving records from tables that contain foreign keys, my DB is wide but I'll simplify the problem, in a typical REGION - > CITY - > COMUNA
REGION Table
Table CITY
Primary Key CITY
Foreign Keys CITY
COMUNA table
Primary Key COMUNA
Foreign Keys COMUNA
I am executing simple sentences such as the following:
SELECT r FROM Region r
SELECT c FROM Ciudad c
SELECT c FROM Comuna c
With these queries, what I want is, in the first, all the records in the REGION table, in the second, all the records in the CITY table, in the third, all the records in the COMUNA table. But, for example for the query of COMUNA I am getting the following result:
And I get very similar results for the other two queries, I do not want this, I want, for the example that I pose, all the records of the COMUNA table without more, but it is bringing me the relationship and also that is not bringing all the records of the table COMUNA , only the first record ("Independence") and its relationships are bringing me, but that table has more records.
I am using Netbeans to generate the code automatically from the Entity Classes, and the Fetch by default is LAZY, I understand that this is fine. I am using Postgresql, I have already tried to change the LAZY by EAGER in the tables and the result is the same.
By the way, these examples are based in Chile, the country is divided into Regions, which in other countries are STATES and the Communes in other countries are called MUNICIPALITIES, it is only to put them a bit in context.
I know that a possible solution is not to inform the BD about the relationships between tables (Foreign keys), but that should not be the solution, that is, it is not the DUTY TO BE.
Here is the code I was asked for in the comments:
The implementation of the service
Netbeans generates an abstract, this is the abstract
These are the libraries that automatically generate me the JSON for exit and entry to the service, really I do not configure anything of these libraries, I only included them and they work so far for what I want that is to send and receive JSON without touching it
Here part of the code that generates netbeans, the rest are getters and setters