-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: NonUniqueObjectException während makePersistent(...)
PostPosted: Mon Aug 21, 2006 12:11 pm 
Newbie

Joined: Fri Aug 18, 2006 8:14 am
Posts: 3
Location: Switzerland
Hallo zusammen

Ich versuche mit Hibernate Daten in einer Datenbank zu speichern. Um dies zu tun, erstellte ich die nötigen DAOs, Modelle, die HibernateUtil Klasse, usw. Dies anhand des Codes von Hibernate in Action Second Edition (HiA_SE).

Wenn ich versuche über das DAO Objekte zu speichern, bekomme ich die folgende Exception

    Exception in thread "main" org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [ch.teamrg.dev.rgrepd.model.Checksum#0]
    at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:556)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:258)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:216)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:494)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:490)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
    at $Proxy0.saveOrUpdate(Unknown Source)
    at ch.teamrg.dev.rgrepd.dao.hibernate.GenericHibernateDAO.makePersistent(GenericHibernateDAO.java:75)
    at ch.teamrg.dev.rgrepd.test.model.InsertData.main(InsertData.java:28)


Die Exception bekomme ich beim Versuch, das Objekt "checksum2" zu speichern. Die DAOFactory ist gleich wie die aus dem SVN.

Code:
public class InsertData {
   static private void beginTransaction() {
      HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
   }
   
   static private void commitTransaction() {
      HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
   }
   
   public static void main(String[] args) {
      DAOFactory daoFactory = DAOFactory.instance(DAOFactory.HIBERNATE);
      
      /*
       * Checksum
       */
      ChecksumDAO checksumDAO = daoFactory.getChecksumDAO();
      
      beginTransaction();
      Checksum checksum1 = new Checksum("md5", "abcdefgmd5");
      Checksum checksum2 = new Checksum("sha-1", "jklmnopqsha1");
      checksumDAO.makePersistent(checksum1);
      checksumDAO.makePersistent(checksum2);
      commitTransaction();
      
   }
}


Was mache ich falsch? Vielen Dank für eure Hilfe.
Tux


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 21, 2006 4:21 pm 
Newbie

Joined: Fri Aug 18, 2006 8:14 am
Posts: 3
Location: Switzerland
Problem gelöst

Und wieder mal eine total unnötige Frage. Habe vergessen in der Checksum.hbm.xml den id generator von assigned auf native zu stellen. Dann wollte er zwei gleiche Objekte mit gleicher ID (= null) einfügen. Das verhindert Hibernate aber. Demzufolge Exception.

Sorry


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.