Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping a unidirectional OneToMany association on a wrapper object using JPA
    primarykey
    data
    text
    <p>I am converting Hibernate configuration over to using JPA. The current configuration has an AlertPref class (ALERT_PREF table) with a collection of Long types that are primary key values from the ALERT_CATEGORY table. There is an ALERT_PREF_CATEGORY junction table that joins the two. I could setup this relationship in JPA by defining the junction table as an Entity class and having a collection of AlertPrefCategory objects instead of Long IDs in the AlertPref class, but I want to avoid this if possible, and instead setup a uni-directional mapping from AlertPref to the Long IDs. Some of the legacy code uses the IDs, and it would be difficult to change this code.</p> <p>Here's the current class tag in the Hibernate config, which works fine:</p> <pre><code>&lt;class name="AlertPref" table="ALERT_PREF"&gt; &lt;id name="alertPrefId" column="ALERT_PREF_ID" type="long"&gt; &lt;generator class="hilo"&gt; &lt;param name="max_lo"&gt;100&lt;/param&gt; &lt;/generator&gt; &lt;/id&gt; &lt;property name="userId" column="USER_ID" type="string" not-null="true" /&gt; &lt;set name="excludedCategoryIds" table="ALERT_PREF_CATEGORY" cascade="all,delete-orphan"&gt; &lt;key column="ALERT_PREF_ID" /&gt; &lt;element column="EXCLUDED_CATEGORY_ID" type="long" /&gt; &lt;/set&gt; &lt;/class&gt; </code></pre> <p>Here is what I tried to use in JPA, but it is throwing the exception "Use of @OneToMany or @ManyToMany targeting an unmapped class: AlertPref.excludedCategoryIds[java.lang.Long]"</p> <pre><code>@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&lt;Long&gt; 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&lt;Long&gt; getExcludedCategoryIds() { return excludedCategoryIds; } /** * @param excludedCategoryIds the excludedCategoryIds to set */ public void setExcludedCategoryIds(Set&lt;Long&gt; excludedCategoryIds) { this.excludedCategoryIds = excludedCategoryIds; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload