Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate - one table multiple entities
    primarykey
    data
    text
    <p>Firstly, I have read <a href="https://stackoverflow.com/questions/9291969/hibernate-one-table-with-multiple-entities">Hibernate - One table with multiple entities?</a>.</p> <p>However, I would like to map two entities to the same table, but I would like both of them to be entities, which I can select from. What I mean:</p> <ul> <li>One table: Person (id, name, dateOfBirth, city, street, zipcode).</li> <li>Two Entities: Person (id, name, dateOfBirth), Address (id, city, street, zipcode).</li> </ul> <p>So it's a 1:1 relationship between Entities, but still 1 table in DB.</p> <p>If I do it using the proposed solution (component keyword) in the above link, I can't query Address directly (I can access it via Person entity). And I want to be able to do</p> <pre><code>session.createCriteria(Adres.class) </code></pre> <p>How do I do that?</p> <p>UPDATE: I tried the one-to-one association between entities, in Address mapping:</p> <pre><code>&lt;one-to-one name="Person " class="model_mapowanie_xml.Person "/&gt; </code></pre> <p>and in Person mapping:</p> <pre><code>&lt;one-to-one name="Address" class="model_mapowanie_xml.Address "/&gt; </code></pre> <p>Both classes have fields referring to the other one. Selecting records works fine for that. However, how can I add in one transaction a record using both entities? (Id is db-generated)</p> <pre><code>Address ad = new Address(); ad.setProperty("Sydney"); Person p = new Person(); p.setProperty("John"); p.setAddress(ad); session.save(p); </code></pre> <p>and only Person part is saved, the address property remains empty.</p>
    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.
 

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