Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate ManyToMany does not work when using Inheritance
    primarykey
    data
    text
    <p>I just refactor a Project to use Hibernate (4.2.4.Final) with Inheritance. But I got trouble with ManyToMany annotation.</p> <p>I have a base File Class like this:</p> <pre><code>@Entity @Table(name = "file") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "descriminator", length = 25) public abstract class File { @Id @Column(name = "id", unique = true, nullable = false, length = 256) private String id; } </code></pre> <p>and a special Inheritance class like this: </p> <pre><code>@Entity @DiscriminatorValue("ISSUE_HISTORY_ATTACHMENT") @Data public class IssueHistoryAttachment extends File { @ManyToOne(fetch = FetchType.LAZY) @JoinTable(name = "issue_history_attachment", joinColumns = { @JoinColumn(name = "attachment_id", nullable = false, unique = true) }, inverseJoinColumns = { @JoinColumn(name = "issue_history_id", nullable = false)}) private IssueHistory history; } </code></pre> <p>This IssueHistoryAttachment Class is also referenced in my IssueHistory Class.</p> <pre><code>@Entity @Table(name = "issue_history") @TableGenerator(name="tg", table="hibernate_sequences",pkColumnName="sequence_name", valueColumnName="sequence_next_hi_value", allocationSize=1) public class IssueHistory implements java.io.Serializable { @Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "tg") @Column(name = "id", unique = true, nullable = false) private int id; // some other fields @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "issue_history_attachment", joinColumns = { @JoinColumn(name = "issue_history_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "attachment_id", nullable = false, unique = true) }) private Set&lt;IssueHistoryAttachment&gt; attachments = new HashSet&lt;IssueHistoryAttachment&gt;(); } </code></pre> <p>When i now store a IssueHistory Instance with two Attachments, all this fields are correctly saved in my database.</p> <p>I got 2 new entries in the <em>file</em> table, one new entry in the *issue_history* table and two correct entries in the relation table *issue_history_attachment*.</p> <p>So at this points all thinks are looking fine. But when I try to read the Values Attachment Set in the IssueHistory Instance <strong>only contains one element instead of two</strong> like stored in the database.</p> <p>Any suggestions how to solve this?</p>
    singulars
    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.
 

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