-->
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: XML-to-database Association
PostPosted: Wed Oct 07, 2009 11:59 am 
Newbie

Joined: Wed Oct 07, 2009 11:21 am
Posts: 1
hi guys..... I'm a newbie of Hibernate, so please exscuse me for the stupid questions :)

I'm developing a little app that import an XML-file into mysql database whit Hiberante. I readed the official guide and other online guide for the one-to-many relation but I have a little problem about it....

In my app there is a simple Parent/Child ( one-to-many ) relation between the class "anagrafica_proprietario" and the class "macchine" infact "anagrafica_proprietario" is the Parente and "macchine" is the child.

I wrote this mapping:
Code:
<hibernate-mapping>
    <class entity-name="anagrafica_proprietario" node="anagrafica_proprietario" table="t_aziende_agricole">
        <id name="id_azienda_agricola" type="int" column="id_azienda_agricola">
            <generator class="native"/>
        </id>
        <property name="ragione_sociale" column="ragione_sociale"  node="ragione_sociale" type="string"/>
        <property name="cod_fiscale" column="cod_fiscale"  node="cod_fiscale" type="string"/>
        <property name="cognome" node="cognome" column="cognome"  type="string"/>
        <property name="nome" node="nome" column="nome" type="string"/>
        <property name="indirizzo" column="indirizzo"  node="indirizzo" type="string"/>
        <property name="cap" column="cap"  node="cap" type="string"/>
        <property name="citta" column="citta"  node="citta" type="string"/>
        <property name="provincia" node="provincia" column="provincia"  type="string"/>
        <property name="n_telefono" column="n_telefono"  node="n_telefono" type="string"/>
        <property name="n_fax" column="n_fax"  node="n_fax" type="string"/>
        <property name="mail" column="mail"  node="mail" type="string"/>
        <property name="p_iva" column="p_iva"  node="p_iva" type="string"/>
        <property name="cua" column="cua"  node="cua" type="string"/>
       
        <set name="macchine" table="t_macchine" cascade="all" inverse="true">
            <key column="id_azienda_agricola" />
            <one-to-many class="macchine" />
        </set>

    </class>

    <class entity-name="macchine" node="macchina" table="t_macchine">
        <composite-id>
            <key-property name="marca" column="marca"  node="marca" type="string"/>
            <key-property name="modello" node="modello" column="modello"  type="string"/>
        </composite-id>
        <property name="n_matricola_ce_telaio" node="n_matricola_ce_telaio" column="n_matricola_ce_telaio" type="string"/>
        <property name="certificazione" node="certificazione" column="certificazione" type="string"/>
        <property name="anno_di_costruzione" node="anno_di_costruzione" column="anno_di_costruzione" type="string"/>
   
     <many-to-one name="azienda" class="anagrafica_proprietario" column="id_azienda_agricola" />
    </class>
</hibernate-mapping>


so i wrote this simply XML-File:
Code:
<irromono_int>
   <anagrafica_proprietario>
      <cod_fiscale>a</cod_fiscale>
      <nome>a</nome>
      <cognome>a</cognome>
      <ragione_sociale>a</ragione_sociale>
      <indirizzo>a</indirizzo>
      <cap>a</cap>
      <citta>a</citta>
      <provincia>a</provincia>
      <n_telefono>a</n_telefono>
      <n_fax>a</n_fax>
      <mail>a</mail>
      <p_iva>0.0</p_iva>
      <cua>a</cua>
      <macchine>
         <marca>a</marca>
         <modello>a</modello>
         <n_matricola_ce_telaio>a</n_matricola_ce_telaio>
         <anno_di_costruzione>aaaa</anno_di_costruzione>
         <certificazione>aaaaaaaaaaaaaaaaaaaa</certificazione>
      </macchine>
   </anagrafica_proprietario>
</irromono_int>



after i wrote a simple java app for import the xml whit hibernate..... after the run of the application this is the log ( I think it's a normal log):
Code:
7-ott-2009 17.55.21 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
7-ott-2009 17.55.21 org.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=hiber, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/prova_hibernate, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver}
7-ott-2009 17.55.21 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
7-ott-2009 17.55.21 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
7-ott-2009 17.55.21 org.hibernate.cfg.Configuration addFile
INFO: Reading mappings from file: C:\Documents and Settings\emilio.petrangeli.ITHAN\Documenti\NetBeansProjects\ProvaHibernate\src\irronet.hbm.xml
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: anagrafica_proprietario -> t_aziende_agricole
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: macchine -> t_macchine
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: controlli -> t_controlli
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: dati_controllo -> t_dati_controllo
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: voci_controllo -> t_voci_controllo
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: id_parametro -> t_id_parametro
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: anagrafica_proprietario.macchine -> t_macchine
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: macchine.controlli -> t_controlli
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: controlli.dati_controllo -> t_dati_controllo
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: controlli.voci_controllo -> t_voci_controllo
7-ott-2009 17.55.22 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: voci_controllo.id_parametro -> t_id_parametro
7-ott-2009 17.55.22 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
7-ott-2009 17.55.22 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
7-ott-2009 17.55.22 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
7-ott-2009 17.55.22 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/prova_hibernate
7-ott-2009 17.55.22 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=hiber, password=****}
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.41-community-nt-log
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
7-ott-2009 17.55.22 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
7-ott-2009 17.55.22 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
7-ott-2009 17.55.22 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
7-ott-2009 17.55.22 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
7-ott-2009 17.55.22 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
7-ott-2009 17.55.22 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
7-ott-2009 17.55.22 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured


after batch I can find the record in the table, but in the table "t_macchine" the value of "id_azienda_agricola" column is always null ...... i need that "t_macchine"."id_azienda_agricola" = "t_aziende_agricole"."id_azienda_agricola"

these are the 2 table after the batch...
"t_aziende_agricole"
Image

"t_macchine"
Image


where is the mistake? How can i resolve this problem???

thank you very much!


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.