Hi all,
I' have been using Hibernate for a couple of years and I always found what I needed inside of that excellent framework... except for the issue I'm currently facing...
Here is what I need :
On the database side, I have got 2 tables : tb_client and tb_client_def. Here is my database structure :
Code:
tb_client
integer Id
tb_client_def
integer client_id
varchar first_name
varchar last_name
date start_date
date end_date
As you can guess, I generally have several client definitions for one client. But I am mostly interested in the current one (for each client, there is
only one client_def that matches tb_client_def.start_date < system.current_date < tb_client_def.end_date).
On the java side, I would like to have a POJO as follows :
Code:
public class Client {
private int id;
private String firstName;
private String lastName;
private Date startDate;
private Date endDate;
}
In the Hibernate mapping, I tried to use a join-table, but I did not find a way to add my search criteria on a join table (tb_client_def.start_date < system.current_date < tb_client_def.end_date).
At the moment, the only workaround I found is to create a view in my database, that returns the current client according to my criteria. I would have prefered to use Hibernate instead of relying on the database.
Did someone ever do that with Hibernate ?