Hi all,
I must insert the objects Company, MonthlyFee and Transaction Tax.
I´m trying to insert objects into database, but occurs
the problem specified bellow when, in the java
code, I try to execute dataSource.insert(monthlyFee, session);
Hibernate version: 2.0.2
Mapping documents:
Code:
<!-- Commpany -->
<hibernate-mapping>
<class name="manager.Company" table="empresa">
<id name="cnpj" column="cnpj">
<generator class="assigned"/>
</id>
<property name="name" column="nome"/>
<property name="corporateName" column="razao_social"/>
<property name="address" column="logradouro"/>
<property name="number" column="numero"/>
<property name="complement" column="complemento"/>
<property name="burgh" column="bairro"/>
<many-to-one name="city" column="id_cidade"
class="manager.City"/>
<one-to-one name="transactionTax" class="transaction.TransactionTax"
constrained="false" outer-join="true"/>
<bag name="monthlyFees" inverse="true" lazy="false">
<key column="cnpj"/>
<one-to-many class="access.MonthlyFee"/>
</bag>
</class>
</hibernate-mapping>
<!-- transactionTax -->
<hibernate-mapping>
<class name="transaction.TransactionTax" table="transacao_taxa">
<id name="cnpj" column="cnpj">
<generator class="foreign">
<param name="property">company</param>
</generator>
</id>
<one-to-one constrained="true" outer-join="false" name="company"
class="manager.Company"/>
<property name="fgTransactionTax" column="fg_transacao_taxa"/>
<property name="value" column="valor"/>
<property name="percentage" column="porcentagem"/>
<property name="limit" column="limite"/>
</class>
</hibernate-mapping>
<!-- monthlyFees -->
<hibernate-mapping>
<class name="access.MonthlyFee" table="mensalidade">
<id name="idMonthlyFee" column="id_mensalidade">
<generator class="assigned"/>
</id>
<many-to-one name="company" column="cnpj"
class="manager.Company"/>
<many-to-one name="expirationDay" column="id_dia_vencimento"
class="access.ExpirationDay"/>
<property name="value" column="valor"/>
<many-to-one name="monthlyFeeStatus" column="id_mensalidade_status"
class="access.MonthlyFeeStatus"/>
<many-to-one name="companyStatus" column="id_empresa_status"
class="manager.CompanyStatus"/>
<property name="dtPayment" column="dt_pagamento"/>
<property name="dtExpiration" column="dt_vencimento"/>
<property name="tpCharge" column="tp_cobranca"/>
<property name="agency" column="agencia"/>
<property name="cdCustomer" column="cd_cliente"/>
<property name="dtGeneration" column="dt_geracao"/>
<bag name="parcels" inverse="true" lazy="false">
<key column="id_mensalidade"/>
<one-to-many class="trip.Parcel"/>
</bag>
<bag name="tolls" inverse="true" lazy="false">
<key column="id_mensalidade"/>
<one-to-many class="trip.Toll"/>
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
session = dataSource.openSession();
tx = session.beginTransaction();
// --- inserts the company ---
dataSource.insert(company, session);
// --- inserts the unique Monthlyfee from the list ---
MonthlyFee monthlyFee = (MonthlyFee) company.getMonthlyFees().get(0);
dataSource.insert(monthlyFee, session);
// --- inserts the transaction tax ---
TransactionTax transactionTax = company.getTransactionTax();
dataSource.insert(transactionTax, session);
Full stack trace of any exception that occurs:Code:
net.sf.hibernate.HibernateException: Found shared references to a collection
Name and version of the database you are using: Oracle 8iThe generated SQL (show_sql=true):Code:
2005-01-26 09:18:46,031 - INFO STDOUT - Hibernate: insert into empresa (nome, razao_social, logradouro, numero, complemento, bairro, id_cidade, cnpj) values (?, ?, ?, ?, ?, ?, ?, ?)
Please, somebody can help me???
thanks!
[/code]