Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate collection mapping with list and super entity class
    text
    copied!<p>here i am again in my self learning hibernate and personal experiment project to gain more understanding. Here is the description of my environment: i have a super model entity that all my model inherit from.it has only id property i use the genericDAO pattern found on hibernate web site. Now my problem is that i use list instead of set for my one to many mapping (there is no need to avoid duplication here) and when i reference the super entity id in list index or list-index property i have this error : org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session here is the super entity interface </p> <pre><code>public interface Model extends Serializable { public Long getId(); public void setId(Long id); } //here is its implementation.they are not in the same physical file public abstract class ModelImpl implements Model { private Long id; public Long getId() { return id; } public void setId(Long id) { this.id = id; } </code></pre> <p>} </p> <p>here is it's mapping file</p> <pre><code>&lt;class abstract="true" name="ModelImpl"&gt; &lt;!--i removed doctype and stuffs--&gt; &lt;id name="id"&gt; &lt;generator class="assigned"/&gt; &lt;/id&gt; &lt;/class&gt; </code></pre> <p>here is on pojo interface this is my parent </p> <pre><code>public interface Message extends Model { Date getDateSent(); String getGlobalStatus(); </code></pre> <p>} //its implementation is here but on different physical file public class MessageImpl extends ModelImpl implements Message{ private String globalStatus; private List response = new ArrayList(); private Date dateSent; //setters and getters.... }</p> <p>its mapping file is like so :</p> <pre><code>&lt;union-subclass extends="ModelImpl" name="MessageImpl"&gt; &lt;property name="globalStatus"/&gt; &lt;property name="dateSent" type="timestamp"/&gt; </code></pre> <p> &lt;/set>--> </p> <p>i commented the set because its was given a casting error which makes me realize my error so the Response class which is the parent is here :</p> <pre><code>public interface Response extends Model { String getGatewayMessageId(); Message getMessageId(); } //its implementation but in different physical file public class ResponseImpl extends ModelImpl implements Response{ private static final long serialVersionUID = 1L; private Message messageId; private String gatewayMessageId; //setters and getters.. } </code></pre> <p>so that is basically that.now during my test when i try to save message with its children it throws this :</p> <blockquote> <p>org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session</p> </blockquote> <p>i can do all persitent methods exception the one i just talked about. i'm a bit lost here coz all of them are inheriting Model id so what am i doing wrong? thanks for reading.I dont' really understand the problem here.</p>
 

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