-->
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.  [ 6 posts ] 
Author Message
 Post subject: Verknüpfungstabelle wird nicht befüllt
PostPosted: Thu Aug 31, 2006 8:45 am 
Beginner
Beginner

Joined: Thu Aug 31, 2006 7:41 am
Posts: 24
Hi,

Ich hab hier ein Problem mit einer n:m Beziehung, die zugehörige Verknüpfungstabelle wird nicht gefüllt. Die mapping Dateien sind IMHO korrekt:

Code:
<hibernate-mapping>
    <class name="de.zgdv.rostock.ceismedia.hibernate.Media" table="media" catalog="ceismedia">
        <comment></comment>
        <id name="id" type="int">
            <column name="id" />
            <generator class="native" />
        </id>
       <set name="keywords" table="media2keyword" cascade="persist,merge,save-update" lazy="true">
            <key column="Media_id" not-null="true"/>
            <many-to-many column="Keyword_id" class="de.zgdv.rostock.ceismedia.hibernate.Keyword" />
        </set>
    </class>
</hibernate-mapping>
<hibernate-mapping>
    <class name="de.zgdv.rostock.ceismedia.hibernate.Keyword" table="keyword" catalog="ceismedia">
        <comment></comment>
        <id name="id" type="int">
            <column name="id" />
            <generator class="native" />
        </id>
        <set name="medias" table="media2keyword" inverse="true" lazy="true">
            <key column="Keyword_id" not-null="true" />
            <many-to-many column="Media_id" class="de.zgdv.rostock.ceismedia.hibernate.Media" />
        </set>
    </class>
</hibernate-mapping>


Abspeichern tue ich ueber:

Code:
Media mi = new Media();
Keyword k = new Keyword();
k.setLabel("Foo");
k.getMedias().add(mi);
mi.getKeywords().add(k);
session.saveOrUpdate(mi);


Ich hab schon diverse Sachen durchprobiert, lazy=true, mit und ohne cascade, die Fremdschluesselbedingungen explizit angegeben. Nichts hilft.

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 11:14 am 
Beginner
Beginner

Joined: Thu Jul 20, 2006 12:08 pm
Posts: 21
Location: Germany
bitte mal das log posten.

gruesse

marlon

_________________
marlon
---
don't hesitate to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 11:18 am 
Beginner
Beginner

Joined: Thu Jul 20, 2006 12:08 pm
Posts: 21
Location: Germany
habe grade keine doku zur hand, aber setze doch mal das inverse=true auf der media-seite. AFAIK ist dies seite wo man das inverse attribut-seite setzt read-only.

_________________
marlon
---
don't hesitate to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 6:01 am 
Beginner
Beginner

Joined: Thu Aug 31, 2006 7:41 am
Posts: 24
marlon wrote:
bitte mal das log posten.


Unten ist der Ausschnitt von Hibernate. Ich kann erstmal nichts verdaechtiges erkennen, ausser eben dass nur die inserts fuer die beiden Datentabellen media und keyword ausgeführt werden aber nicht für die join-table.

Code:
Environment::<clinit> - INFO - Hibernate 3.1.3
Environment::<clinit> - INFO - hibernate.properties not found
Environment::<clinit> - INFO - using CGLIB reflection optimizer
Environment::<clinit> - INFO - using JDK 1.4 java.sql.Timestamp handling
Configuration::configure - INFO - configuring from resource: /hibernate.cfg.xml
Configuration::getConfigurationInputStream - INFO - Configuration resource: /hibernate.cfg.xml
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Language.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Language -> language
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Place.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Place -> place
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Place.medias -> media2place
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Ticket.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Ticket -> ticket
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Ticket.medias -> media2ticket
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Derivativetype.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Derivativetype -> derivativetype
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Keyword.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Keyword -> keyword
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Keyword.medias -> media2keyword
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Person.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Person -> person
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Person.medias -> media2person
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Mimetype.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Mimetype -> mimetype
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Creator.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Creator -> creator
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Ast.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Ast -> ast
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Ast.medias -> media2ast
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Media.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Media -> media
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.tickets -> media2ticket
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.places -> media2place
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.keywords -> media2keyword
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.typeclassifications -> media2typeclassification
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.asts -> media2ast
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.systemstructures -> media2systemstructure
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.persons -> media2person
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Typeclassification.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Typeclassification -> typeclassification
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Typeclassification.medias -> media2typeclassification
Configuration::addResource - INFO - Reading mappings from resource: de/zgdv/rostock/ceismedia/hibernate/Systemstructure.hbm.xml
HbmBinder::bindRootPersistentClassCommonValues - INFO - Mapping class: de.zgdv.rostock.ceismedia.hibernate.Systemstructure -> systemstructure
HbmBinder::bindCollection - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Systemstructure.medias -> media2systemstructure
Configuration::doConfigure - INFO - Configured SessionFactory: null
HbmBinder::bindCollectionSecondPass - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Language.medias -> media
HbmBinder::bindCollectionSecondPass - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Derivativetype.medias -> media
HbmBinder::bindCollectionSecondPass - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Mimetype.medias -> media
HbmBinder::bindCollectionSecondPass - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Creator.medias -> media
HbmBinder::bindCollectionSecondPass - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.derivatives -> media
HbmBinder::bindCollectionSecondPass - INFO - Mapping collection: de.zgdv.rostock.ceismedia.hibernate.Media.revisions -> media
DriverManagerConnectionProvider::configure - INFO - Using Hibernate built-in connection pool (not for production use!)
DriverManagerConnectionProvider::configure - INFO - Hibernate connection pool size: 20
DriverManagerConnectionProvider::configure - INFO - autocommit mode: false
DriverManagerConnectionProvider::configure - INFO - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://irania/ceismedia
DriverManagerConnectionProvider::configure - INFO - connection properties: {user=ceismedia, password=****}
SettingsFactory::buildSettings - INFO - RDBMS: MySQL, version: 4.1.12a-nt-max
SettingsFactory::buildSettings - INFO - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.13 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
Dialect::<init> - INFO - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
TransactionFactoryFactory::buildTransactionFactory - INFO - Using default transaction strategy (direct JDBC transactions)
TransactionManagerLookupFactory::getTransactionManagerLookup - INFO - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
SettingsFactory::buildSettings - INFO - Automatic flush during beforeCompletion(): disabled
SettingsFactory::buildSettings - INFO - Automatic session close at end of transaction: disabled
SettingsFactory::buildSettings - INFO - JDBC batch size: 15
SettingsFactory::buildSettings - INFO - JDBC batch updates for versioned data: disabled
SettingsFactory::buildSettings - INFO - Scrollable result sets: enabled
SettingsFactory::buildSettings - INFO - JDBC3 getGeneratedKeys(): enabled
SettingsFactory::buildSettings - INFO - Connection release mode: auto
SettingsFactory::buildSettings - INFO - Maximum outer join fetch depth: 2
SettingsFactory::buildSettings - INFO - Default batch fetch size: 1
SettingsFactory::buildSettings - INFO - Generate SQL with comments: disabled
SettingsFactory::buildSettings - INFO - Order SQL updates by primary key: disabled
SettingsFactory::createQueryTranslatorFactory - INFO - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
ASTQueryTranslatorFactory::<init> - INFO - Using ASTQueryTranslatorFactory
SettingsFactory::buildSettings - INFO - Query language substitutions: {}
SettingsFactory::buildSettings - INFO - Second-level cache: enabled
SettingsFactory::buildSettings - INFO - Query cache: disabled
SettingsFactory::createCacheProvider - INFO - Cache provider: org.hibernate.cache.NoCacheProvider
SettingsFactory::buildSettings - INFO - Optimize cache for minimal puts: disabled
SettingsFactory::buildSettings - INFO - Structured second-level cache entries: disabled
SettingsFactory::buildSettings - INFO - Echoing all SQL to stdout
SettingsFactory::buildSettings - INFO - Statistics: disabled
SettingsFactory::buildSettings - INFO - Deleted entity synthetic identifier rollback: disabled
SettingsFactory::buildSettings - INFO - Default entity-mode: pojo
SessionFactoryImpl::<init> - INFO - building session factory
SessionFactoryObjectFactory::addInstance - INFO - Not binding factory to JNDI, no JNDI name configured
Hibernate: select keyword0_.id as col_0_0_ from keyword keyword0_ where keyword0_.uri=?
Hibernate: insert into media (Derivative_id, Creator_id, Revision_id, MimeType_id, DerivativeType_id, Language_id, width, height, locationUri, visibility, mediaType, name, description, date, uploaddate, copyright, revision) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into keyword (uri, label) values (?, ?)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 6:09 am 
Beginner
Beginner

Joined: Thu Aug 31, 2006 7:41 am
Posts: 24
marlon wrote:
habe grade keine doku zur hand, aber setze doch mal das inverse=true auf der media-seite. AFAIK ist dies seite wo man das inverse attribut-seite setzt read-only.


Soweit ich die Hibernate Referenz verstehe ist das inverse nur dazu da Hibernate zu sagen von welcher Seite er die Beziehung nicht in die Datenbank schreiben muss. Also wenn ein Keyword abgespeichert wird muss die Beziehungstabelle nicht gefüllt werden. Wenn ein Media Objekt abgelegt wird schon. Von daher wuerde ich sagen ist das schon an der richtigen Stelle.

Tatsaechlich macht das absolut keinen Unterschied (grad nochmal getestet).

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 7:03 am 
Beginner
Beginner

Joined: Thu Aug 31, 2006 7:41 am
Posts: 24
apaku wrote:
marlon wrote:
habe grade keine doku zur hand, aber setze doch mal das inverse=true auf der media-seite. AFAIK ist dies seite wo man das inverse attribut-seite setzt read-only.


Soweit ich die Hibernate Referenz verstehe ist das inverse nur dazu da Hibernate zu sagen von welcher Seite er die Beziehung nicht in die Datenbank schreiben muss. Also wenn ein Keyword abgespeichert wird muss die Beziehungstabelle nicht gefüllt werden. Wenn ein Media Objekt abgelegt wird schon. Von daher wuerde ich sagen ist das schon an der richtigen Stelle.

Tatsaechlich macht das absolut keinen Unterschied (grad nochmal getestet).

Andreas


So, ich antworte mir mal selbst:

Die Loesung war statt

hibsession.connection().commit();
einfach
hibsession.getTransaction().commit();

auszufuehren, da ich vorher mittels hibsession.beginTransaction() eine Transaktion begonnen habe.

Falls noch jemand ueber sowas stolpert.

Andreas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.