简体   繁体   中英

Hibernate one-to-many mapping - to fetch only one mapped record based on a criteria

Problem : There is a transaction table and status table with one-to-many mapping. One transaction can have multiple statuses like failed, partially paid and success. How to fetch the latest status of a transaction.

ie, If I have a transaction with multiple statuses like failed and success of which success is the latest one. Is there any way to configure the same in hibernate to fetch one record from status table based on date field or any other field?

I have been searching for best way for my problem, though I have some ways to do the same using comparable and compare to in java, I am still wondering if there is any solution that hibernate provides where we can simply configure it in hbm files and get the output.

Thanks in advance.

You can try Filters in hibernate by which you can filter out the data in OneToMany Collection. Also take a look here as an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM