Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mapping a unidirectional OneToMany association on a wrapper object using JPA
- <class name="AlertPref" table="ALERT_PREF">
- <id name="alertPrefId" column="ALERT_PREF_ID" type="long">
- <generator class="hilo">
- <param name="max_lo">100</param>
- </generator>
- </id>
- <property name="userId" column="USER_ID" type="string"
- not-null="true" />
- <set name="excludedCategoryIds" table="ALERT_PREF_CATEGORY" cascade="all,delete-orphan">
- <key column="ALERT_PREF_ID" />
- <element column="EXCLUDED_CATEGORY_ID" type="long" />
- </set>
- </class>
- @Entity
- @Table(name = "ALERT_PREF")
- public class AlertPref {
- @Id
- @TableGenerator(name = "table_gen", allocationSize = 1)
- @GeneratedValue(strategy = GenerationType.TABLE, generator = "table_gen")
- @Column(name = "ALERT_PREF_ID")
- private long alertPrefId;
- @Column(name = "USER_ID", nullable = false)
- private String userId;
- @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinTable(name = "ALERT_PREF_CATEGORY",
- joinColumns = @JoinColumn(name = "ALERT_PREF_ID"),
- inverseJoinColumns = @JoinColumn(name = "EXCLUDED_CATEGORY_ID"))
- private Set<Long> excludedCategoryIds;
- /**
- * @return Returns the alertPrefId.
- */
- public long getAlertPrefId() {
- return alertPrefId;
- }
- /**
- * @param alertPrefId
- * The alertPrefId to set.
- */
- public void setAlertPrefId(long alertPrefId) {
- this.alertPrefId = alertPrefId;
- }
- /**
- * @return Returns the userId.
- */
- public String getUserId() {
- return userId;
- }
- /**
- * @param userId
- * The userId to set.
- */
- public void setUserId(String userId) {
- this.userId = userId;
- }
- /**
- * @return the excludedCategoryIds
- */
- public Set<Long> getExcludedCategoryIds() {
- return excludedCategoryIds;
- }
- /**
- * @param excludedCategoryIds the excludedCategoryIds to set
- */
- public void setExcludedCategoryIds(Set<Long> excludedCategoryIds) {
- this.excludedCategoryIds = excludedCategoryIds;
- }
- }
Add Comment
Please, Sign In to add comment