tags:

views:

16

answers:

1

Hello,

I have a table which stores historical data. It's mapped to an Entity with the following fields (I use JPA with Hibernate implementation):

@Entity
@Table(name="items_historical")
public class ItemHistory{
    private Integer id;

    private Date date;

    @Enumerated(EnumType.ORDINAL)
    private StatusEnum status

    @ManyToOne(optional=false)
    private User user;

    @ManyToOne(optional=false)
    private Item item;
}

public enum StatusEnum {
OK, BAD,...//my status
}

In every row I store historical data of another table. I need to get the list of the changes on "status" column: the status, the date and the previous status on a specified item (It would be good as well getting the status and date when status was changed). I don't know if this is possible by using HQL.

Thanks.

+2  A: 

Why don't you use a solution like Hibernate Envers(formerly known as JBoss Envers) for the historical data instead of designing a custom solution? I think you'll find Envers's features quite compelling.

Bozhidar Batsov