Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 1.40 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Howto Persist a Map<Entity, Integer> with JPA?
  2. @Entity
  3. class PerformanceRating{
  4. ....
  5. ....
  6. @ManyToMany(fetch = FetchType.EAGER)
  7. @JoinTable(name = "performance_rating_progress_reward", joinColumns = { @JoinColumn(name = "id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "amount", nullable = false, updatable = false) })
  8. public Map<Progress, Integer> getRewardAmountByProgressMap() {
  9.     return this.rewardAmountByProgressMap;
  10. }
  11.        
  12. Use of @OneToMany or @ManyToMany targeting an unmapped class: fwl.domain.model.PerformanceRating.rewardAmountByProgressMap[java.lang.Integer]
  13.        
  14. rating
  15. ============
  16. id               int(11) PK
  17.        
  18. progress
  19. ============
  20. id               int(11) PK
  21. amount           int(11)
  22.        
  23. progress_has_rating
  24. ============
  25. progress_id      int(11) PK
  26. rating_id        int(11) PK
  27.        
  28. @Entity @Table class Rating {
  29.   @Id long id;
  30.   @ManyToMany(targetEntity = Progress.class,
  31.               cascade = CascadeType.ALL,
  32.               fetch = FetchType.EAGER)
  33.   @JoinTable(name = "progress_has_rating",
  34.              joinColumns = {@JoinColumn(name = "rating_id",
  35.                                         referencedColumnName = "id")},
  36.              inverseJoinColumns = {@JoinColumn(name = "progress_id",
  37.                                                referencedColumnName = "id")})
  38.   Set<Progress> progresses;
  39. }
  40.  
  41. @Entity class Progress {
  42.   @Id long id;
  43.   @Basic long amount;
  44. }