Combine Predicate dengan HQL
Hai kesempatan kali ini saya mau membahas tentang Combine Predicate dengan menggunakan Hibernate Query Language (HQL). Combine predicate terdiri dari
- OR Predicate
- And Predicate
- gabungan
berikut adalah implementasi DAO:
Implementasi unit testing
Sebelum kita coba, berikut adalah data yang saya gunakan:
Setelah itu coba jalankan unit testing pada method testAndOperator()
, maka hasilnya seperti berikut:
Feb 02, 2021 2:54:14 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Hibernate:
select
employeepa0_.id as id1_33_,
employeepa0_.street_address as street_a2_33_,
employeepa0_.job_id as job_id3_33_,
employeepa0_.manager_id as manager_6_33_,
employeepa0_.full_name as full_nam4_33_,
employeepa0_.salary as salary5_33_
from
parentchild.employees employeepa0_
where
employeepa0_.salary>=?
and employeepa0_.job_id=?
[main] INFO com.maryanto.dimas.bootcamp.test.query.hql.TestHQLCombinePredicate - data: [Muhamad Yusuf, Prima, Insan]
[main] INFO com.maryanto.dimas.bootcamp.test.query.hql.TestHQLCombinePredicate - destroy hibernate session!
Kemudian coba jalankan method testOrOperator()
, maka hasilnya seperti berikut:
Feb 02, 2021 2:54:56 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Hibernate:
select
employeepa0_.id as id1_33_,
employeepa0_.street_address as street_a2_33_,
employeepa0_.job_id as job_id3_33_,
employeepa0_.manager_id as manager_6_33_,
employeepa0_.full_name as full_nam4_33_,
employeepa0_.salary as salary5_33_
from
parentchild.employees employeepa0_
where
employeepa0_.salary>=?
or employeepa0_.job_id=?
[main] INFO com.maryanto.dimas.bootcamp.test.query.hql.TestHQLCombinePredicate - data: [Dimas Maryanto, Muhamad Yusuf, Prima, Insan, Hari Sapto Adi, Abdul, Dea, Putri]
[main] INFO com.maryanto.dimas.bootcamp.test.query.hql.TestHQLCombinePredicate - destroy hibernate session!
Kemudian kita coba jalankan method testOrAndOperator()
, maka hasilnya seperti berikut:
Feb 02, 2021 2:55:36 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Hibernate:
select
employeepa0_.id as id1_33_,
employeepa0_.street_address as street_a2_33_,
employeepa0_.job_id as job_id3_33_,
employeepa0_.manager_id as manager_6_33_,
employeepa0_.full_name as full_nam4_33_,
employeepa0_.salary as salary5_33_
from
parentchild.employees employeepa0_
where
employeepa0_.salary>=?
and employeepa0_.job_id=?
or employeepa0_.manager_id is null
[main] INFO com.maryanto.dimas.bootcamp.test.query.hql.TestHQLCombinePredicate - data: [Muhamad Yusuf, Prima, Insan, Hari Sapto Adi, Dea, Putri]
[main] INFO com.maryanto.dimas.bootcamp.test.query.hql.TestHQLCombinePredicate - destroy hibernate session!
Dan yang terakhir coba jalankan method testOrAndWithPriorityOperator()
, maka hasilnya seperti berikut:
Feb 02, 2021 2:56:22 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Hibernate:
select
employeepa0_.id as id1_33_,
employeepa0_.street_address as street_a2_33_,
employeepa0_.job_id as job_id3_33_,
employeepa0_.manager_id as manager_6_33_,
employeepa0_.full_name as full_nam4_33_,
employeepa0_.salary as salary5_33_
from
parentchild.employees employeepa0_
where
employeepa0_.salary>=?
or employeepa0_.job_id=?
and (
employeepa0_.manager_id is null
)
[main] INFO com.maryanto.dimas.bootcamp.test.query.hql.TestHQLCombinePredicate - data: [Dimas Maryanto, Muhamad Yusuf, Prima, Insan, Hari Sapto Adi, Dea, Putri]
[main] INFO com.maryanto.dimas.bootcamp.test.query.hql.TestHQLCombinePredicate - destroy hibernate session!
Yuk simak juga videonya,
Dan jika temen-temen belajar hal baru kali ini jangan lupa buat Like, Subcribe, dan Share ke temen kalian. Terimakasih!!!