-->
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.  [ 1 post ] 
Author Message
 Post subject: @CollectionOfElements werden dupliziert
PostPosted: Wed Dec 05, 2007 6:33 pm 
Newbie

Joined: Sun Nov 25, 2007 10:51 am
Posts: 3
Ich habe eine Collection von Embedable Objects. Diese Objects enthalten noch dazu jeweils eine Blob.
Wenn ich im Rahmen einer Transaktion die Objekte auslese und zum schluss die Transaktion commite, erkennt er die Collection als dirty an und versucht erst den Eintrag zu löschen (was aber noch dazu nicht erfolgreich ist) und dann wieder hinzuzufügen, was die ganze Sache dann verdoppelt.

Hat jemand eine Idee, wie dies verhindern kann?


Hibernate version:
3.2.5.ga

Mapping documents:

Code:
@Entity
@Table(name="keyword")
public class Keyword extends AbstractLastChangeObject
{

  @CollectionOfElements(fetch=FetchType.LAZY)
  Set<Media> media = new HashSet<Media>();
...
}


Code:
@Embeddable
@Cache(usage=CacheConcurrencyStrategy.NONE)
public class Media
{

  @Column(name="filename")
  String filename;
 
  @Column(name="mimetype")
  String mimetype;
 
  @Column(name="length")
  long length;
 
  @Column(name="exturl",length=256)
  String exturl;
 
  @Lob
  @Basic(fetch = FetchType.LAZY)
  Blob data;
 
  @Column(name="pc")
  int pc=1;

  @ManyToOne
  @JoinColumn(name="lang", nullable=true)
  Language lang;
...
}

Code between sessionFactory.openSession() and session.close():

Code:
        _transaction =  _mgr.getTransaction(new DefaultTransactionDefinition(
            TransactionDefinition.PROPAGATION_NESTED));
       
        DetachedCriteria _query = DetachedCriteria.forClass(Keyword.class);
        for (Keyword _key:(List<Keyword>)getHibernateTemplate().findByCriteria(_query))
        {
          for (Media _m:_key.getMedia())
            FileCopyUtils.copy(_m.getInputStream(),new FileOutputStream(new File("tes.dat")));
        }

        // now the Media-Collection will be duplicated when flushing!!!
        _mgr.commit(_transaction);





Full stack trace of any exception that occurs:
keine

Name and version of the database you are using:
postgres 8.2.4
The generated SQL (show_sql=true):

Code:

Hibernate:
    delete
    from
        keyword_media
    where
        keyword_guid=?
        and data=?
        and exturl=?
        and filename=?
        and lang=?
        and length=?
        and mimetype=?
        and pc=?
Hibernate:
    insert
    into
        keyword_media
        (keyword_guid, data, exturl, filename, lang, length, mimetype, pc)
    values
        (?, ?, ?, ?, ?, ?, ?, ?)



[b]Debug level Hibernate log excerpt:[/b]
23:25:17,937 DEBUG AbstractBatcher:382 - about to open ResultSet (open ResultSets: 0, globally: 0)
23:25:17,937 DEBUG Loader:1054 - result set contains (possibly empty) collection: [org.crlx.core.content.Keyword.media#13le5d9_2_1]
23:25:17,937 DEBUG Loader:1173 - result row:
23:25:17,937 DEBUG Loader:985 - found row of collection: [org.crlx.core.content.Keyword.media#13le5d9_2_1]
23:25:17,937 DEBUG EhCache:68 - key: org.crlx.core.content.base.AbstractGUIDObject#de
23:25:17,937 DEBUG AbstractBatcher:389 - about to close ResultSet (open ResultSets: 1, globally: 1)
23:25:17,937 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
23:25:17,937 DEBUG CollectionLoadContext:217 - 1 collections were found in result set for role: org.crlx.core.content.Keyword.media
23:25:17,937 DEBUG CollectionLoadContext:260 - collection fully initialized: [org.crlx.core.content.Keyword.media#13le5d9_2_1]
23:25:17,937 DEBUG CollectionLoadContext:226 - 1 collections initialized for role: org.crlx.core.content.Keyword.media
23:25:17,937 DEBUG StatefulPersistenceContext:790 - initializing non-lazy collections
23:25:17,937 DEBUG Loader:2010 - done loading collection
23:25:17,953 DEBUG JDBCTransaction:103 - commit
23:25:17,953 DEBUG AbstractFlushingEventListener:111 - processing flush-time cascades
23:25:17,953 DEBUG AbstractFlushingEventListener:154 - dirty checking collections
23:25:17,953 DEBUG CollectionEntry:177 - Collection dirty: [org.crlx.core.content.Keyword.media#13le5d9_2_1]
23:25:17,953 DEBUG Collections:176 - Collection found: [org.crlx.core.content.Keyword.categories#13le5d9_2_1], was: [org.crlx.core.content.Keyword.categories#13le5d9_2_1] (uninitialized)
23:25:17,953 DEBUG Collections:176 - Collection found: [org.crlx.core.content.Keyword.languages#13le5d9_2_1], was: [org.crlx.core.content.Keyword.languages#13le5d9_2_1] (uninitialized)
23:25:17,953 DEBUG Collections:176 - Collection found: [org.crlx.core.content.Keyword.media#13le5d9_2_1], was: [org.crlx.core.content.Keyword.media#13le5d9_2_1] (initialized)
23:25:17,953 DEBUG AbstractFlushingEventListener:85 - Flushed: 0 insertions, 0 updates, 0 deletions to 2 objects
23:25:17,953 DEBUG AbstractFlushingEventListener:91 - Flushed: 0 (re)creations, 1 updates, 0 removals to 3 collections
23:25:17,953 DEBUG Printer:83 - listing entities:
23:25:17,953 DEBUG Printer:90 - org.crlx.core.content.Language{guid=de, descr=Deutsch}
23:25:17,953 DEBUG Printer:90 - org.crlx.core.content.Keyword{creationtime=2007-12-05 22:18:33, guid=13le5d9_2_1, languages=<uninitialized>, status=org.crlx.core.content.Status#crx_commited, categories=<uninitialized>, media=[component[data,exturl,filename,lang,length,mimetype,pc]{mimetype=, exturl=http://www.spiegel.de/, pc=1, length=46390, data=org.hibernate.lob.SerializableBlob@1080876, filename=test.html, lang=org.crlx.core.content.Language#de}], lastchange=2007-12-05 22:18:33}
23:25:17,953 DEBUG UpdateTimestampsCache:50 - Pre-invalidating space [keyword_media]
23:25:17,953 DEBUG AbstractCollectionPersister:1204 - Deleting rows of collection: [org.crlx.core.content.Keyword.media#13le5d9_2_1]
23:25:17,953 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
23:25:17,953 DEBUG SQL:401 -
    delete
    from
        keyword_media
    where
        keyword_guid=?
        and data=?
        and exturl=?
        and filename=?
        and lang=?
        and length=?
        and mimetype=?
        and pc=?
Hibernate:
    delete
    from
        keyword_media
    where
        keyword_guid=?
        and data=?
        and exturl=?
        and filename=?
        and lang=?
        and length=?
        and mimetype=?
        and pc=?
23:25:17,968 DEBUG AbstractCollectionPersister:1281 - done deleting collection rows: 1 deleted
23:25:17,968 DEBUG AbstractCollectionPersister:1313 - Inserting rows of collection: [org.crlx.core.content.Keyword.media#13le5d9_2_1]
23:25:17,968 DEBUG AbstractBatcher:44 - Executing batch size: 1
23:25:17,968 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
23:25:17,968 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
23:25:17,968 DEBUG SQL:401 -
    insert
    into
        keyword_media
        (keyword_guid, data, exturl, filename, lang, length, mimetype, pc)
    values
        (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate:
    insert
    into
        keyword_media
        (keyword_guid, data, exturl, filename, lang, length, mimetype, pc)
    values
        (?, ?, ?, ?, ?, ?, ?, ?)
23:25:17,968 DEBUG AbstractCollectionPersister:1390 - done inserting rows: 1 inserted
23:25:17,968 DEBUG AbstractBatcher:44 - Executing batch size: 1
23:25:17,968 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
23:25:17,968 DEBUG JDBCTransaction:193 - re-enabling autocommit
23:25:17,968 DEBUG JDBCTransaction:116 - committed JDBC Connection
23:25:17,968 DEBUG ConnectionManager:302 - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
23:25:17,968 DEBUG UpdateTimestampsCache:65 - Invalidating space [keyword_media], timestamp: 4902475849596928
23:25:17,968 DEBUG ConnectionManager:441 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
23:25:17,968 DEBUG ConnectionManager:302 - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!


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

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.