hello good fellas! 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
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;
}
}
here is it's mapping file
<class abstract="true" name="ModelImpl">
<!--i removed doctype and stuffs-->
<id name="id">
<generator class="assigned"/>
</id>
</class>
here is on pojo interface this is my parent
public interface Message extends Model {
Date getDateSent();
String getGlobalStatus();
} //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.... }
its mapping file is like so :
<union-subclass extends="ModelImpl" name="MessageImpl">
<property name="globalStatus"/>
<property name="dateSent" type="timestamp"/>
-->
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 :
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..
}
so that is basically that.now during my test when i try to save message with its children it throws this :
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
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.