当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Hibernate entity containing one row of joined table

问题描述:

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?

分享给朋友:
您可能感兴趣的文章:
随机阅读: