开发者

Return Map<Key, Value> with condition in Hibernate Annotation

I have a table with the following columns:

id, target (string), audience_group_id, rating (Integer), job_id

target column is a string representation of one of the following values: predi开发者_运维技巧cted, actual, updated

I thought to add method in Job class:

Map<AudienceGroup, Integer( this it the rating)> getAudienceRatingPerPredictedPrograms().

I am stuck with the annotation. How can I tell it to return map that the value in target is "predicted"?


I am stuck with the annotation. How can I tell it to return map that the value in target is "predicted"?

If this is doable (I have some doubts about the table design, this will require some testing), I think you'll have to use the Map annotations (@org.hibernate.annotations.MapKey/MapKeyManyToMany) in conjunction with Hibernate's filtering capabilities to filter the association.

I would first try to map the Map as wanted (probably using MapKeyManyToMany in your case). Once done with the Map, apply the filter.

I've never tested this.

References

  • Hibernate Annotations 3.4 Reference Guide
    • 2.2.5.3. Collections
    • 2.4.6.2.2. Map
    • 2.4.9. Filters
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜