mercredi 12 janvier 2022

Fetch records from Multiple tables having different type of primary key. Hibernate

I have a use case where i need to get records from different tables based on emailAddress, and each of these tables have different type of primary key(String ,Integer etc)

@Entity
Class A{
@Id
Integer ID;
String emailAddress;
}

@Entity
Class  B{
@Id
String ID;
String emailAddress;
}

@Entity
Class C{
@Id
Long ID;
String emailAddr;
}

Now lets say i have email address : test@gmail.com

My use case if to fetch Records associated with this email address from each of these tables and do some processing on the primary Key.

something like

for each table
   get list records with the given emailAddress from that table
   do some processing on primary key

My main problem is fetching the id of the result, since it is of different type for each table. I want do it in a loop.

I'm using JpaRepository for fetching data from database

Aucun commentaire:

Enregistrer un commentaire