Guest User

Untitled

a guest
Aug 19th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. Mapping a unidirectional OneToMany association on a wrapper object using JPA
  2. <class name="AlertPref" table="ALERT_PREF">
  3. <id name="alertPrefId" column="ALERT_PREF_ID" type="long">
  4. <generator class="hilo">
  5. <param name="max_lo">100</param>
  6. </generator>
  7. </id>
  8.  
  9. <property name="userId" column="USER_ID" type="string"
  10. not-null="true" />
  11.  
  12. <set name="excludedCategoryIds" table="ALERT_PREF_CATEGORY" cascade="all,delete-orphan">
  13. <key column="ALERT_PREF_ID" />
  14. <element column="EXCLUDED_CATEGORY_ID" type="long" />
  15. </set>
  16.  
  17. </class>
  18.  
  19. @Entity
  20. @Table(name = "ALERT_PREF")
  21. public class AlertPref {
  22. @Id
  23. @TableGenerator(name = "table_gen", allocationSize = 1)
  24. @GeneratedValue(strategy = GenerationType.TABLE, generator = "table_gen")
  25. @Column(name = "ALERT_PREF_ID")
  26. private long alertPrefId;
  27.  
  28. @Column(name = "USER_ID", nullable = false)
  29. private String userId;
  30.  
  31. @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
  32. @JoinTable(name = "ALERT_PREF_CATEGORY",
  33. joinColumns = @JoinColumn(name = "ALERT_PREF_ID"),
  34. inverseJoinColumns = @JoinColumn(name = "EXCLUDED_CATEGORY_ID"))
  35. private Set<Long> excludedCategoryIds;
  36.  
  37. /**
  38. * @return Returns the alertPrefId.
  39. */
  40. public long getAlertPrefId() {
  41. return alertPrefId;
  42. }
  43.  
  44. /**
  45. * @param alertPrefId
  46. * The alertPrefId to set.
  47. */
  48. public void setAlertPrefId(long alertPrefId) {
  49. this.alertPrefId = alertPrefId;
  50. }
  51.  
  52. /**
  53. * @return Returns the userId.
  54. */
  55. public String getUserId() {
  56. return userId;
  57. }
  58.  
  59. /**
  60. * @param userId
  61. * The userId to set.
  62. */
  63. public void setUserId(String userId) {
  64. this.userId = userId;
  65. }
  66.  
  67. /**
  68. * @return the excludedCategoryIds
  69. */
  70. public Set<Long> getExcludedCategoryIds() {
  71. return excludedCategoryIds;
  72. }
  73.  
  74. /**
  75. * @param excludedCategoryIds the excludedCategoryIds to set
  76. */
  77. public void setExcludedCategoryIds(Set<Long> excludedCategoryIds) {
  78. this.excludedCategoryIds = excludedCategoryIds;
  79. }
  80. }
Add Comment
Please, Sign In to add comment