Note that there are some explanatory texts on larger screens.

plurals
  1. PO@embeddable vs @entity for a mapping a collection
    primarykey
    data
    text
    <p>This must be quite naive but I have a doubt on when to use <code>@Entity</code> and <code>@Embeddable</code>.</p> <p>Say I have a <code>User</code> and <code>Notification</code> class.</p> <pre><code> @Entity public class User{ //other properties @onetomany private List&lt;Notification&gt; notifications; } @Entity public class Notification{ //properties } </code></pre> <p>I understand that there will be tables for class <code>User</code> and <code>Notification</code>, and a third table for mapping. What if I do it like this?</p> <pre><code> @Entity public class User { //other properties @ElementCollection private List&lt;Notification&gt; notifications; } @Embeddable public class Notification{ //properties } </code></pre> <p>I know this won't create a table for <code>Notification</code>. But I can still store my notification objects. I went through the <a href="http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/collections.html#example.collection.mapping.annotations" rel="nofollow noreferrer">documentation</a>, but couple of doubts:</p> <ol> <li>Is it based on whether I want to see class B as a seperate table?</li> <li>Is there a performance difference b/w creating a table and an embeddable object?</li> <li>What can I not do with embeddable object that I can do with a table other than directly querying the table?</li> </ol> <p><strong>NOTES</strong></p> <p>For anyone reading this question, this <a href="https://stackoverflow.com/questions/3418683/jpa-when-to-choose-multivalued-association-vs-element-collection-mapping">question</a> too might help you.</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.
 

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