Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare fields in two different tables using Hibernate?

Tags:

hibernate

hql

I need to compare fields from 2 different tables using Hibernate queries.

Table A has a field which consists of sectionId(eg 1900).

Table B has a field which consists of userId/sectionId(eg e1230-12w11-3ewq-qg22-34qa/1900).

I need to extract sectionId from table B and compare it with sectionId in table A so that I can build a row for a new table. I also need to extract userId from table B and use it as a part of this new row too.

Does hql have the ability to compare fields partially?

like image 573
Best Avatar asked Dec 22 '25 14:12

Best


1 Answers

I think you can do this using JPQL functions: SUBSTRING and LOCATE.

LOCATE will be able to locate the particular character in your input string and will return it's place.
Then you should be able to use SUBSTRING to return just a part of the string based on the index returned by LOCATE.

like image 147
Piotr Nowicki Avatar answered Dec 24 '25 11:12

Piotr Nowicki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!