问题描述:

Is it possible to create a hibernate entity which contains as a member, a single row from another table?

e.g. I have 'events' which are associated with 'things' (one 'thing' has many 'events'):

@Entity()

@Table(name = "event")

public class Event

{

private String eventName;

private Thing thing;

private Timestamp timestamp;

}

@Entity()

@Table(name = "thing")

public class Thing

{

private String thingName;

private Event mostRecentEvent;

}

Is it possible to add an annotation which will join events onto things and get the most recent event.

If not, is there a better way of doing this than having a collection of events on 'thing' and then extracting the 'most recent' in the code? Surely it's better to have this work done by the DB?

相关阅读:
Top