Hi
I am having 2 classes with Bussiness and TaxOffice with many-to-one assossiation
Bussiness
Code:
<class name="Bussiness" table="BUSSINESS">
<id name="id" type="integer" column="BUSSINESS_ID">
<generator class="identity"/>
</id>
<property name="afm" column="AFM" type="string" not-null="true"/>
<property name="name" column="NAME" type="string" not-null="true"/>
<many-to-one name="taxOffice"
class="TaxOffice"
lazy="false"
column="TAX_OFFICE_ID"/>
</class>
TaxOffice
Code:
<class name="TaxOffice" table="TAX_OFFICE">
<id name="id" type="integer" column="TAX_OFFICE_ID">
<generator class="identity"/>
</id>
<property name="code" column="TAX_OFFICE_CODE" type="string"/>
<property name="name" column="TAX_OFFICE_NAME" type="string" not-null="true"/>
</class>
I want sometimes an object
bussiness of Bussiness class not have an object of TaxOffice class so when
am i giving bussiness.setTaxOffice(null) am getting the following error
Quote:
Exception occurred during event dispatching:
org.hibernate.TransientObjectException: object references an unsaved transient i
nstance - save the transient instance before flushing: TaxOffice
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(Fore
ignKeys.java:242)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:430)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:265)
at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:619)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(Abst
ractEntityPersister.java:3151)....
wich means that hibernate tries to update the TaxOffice object first.
I have tried to change the properties on many-to-one like this
Code:
<many-to-one name="taxOffice"
class="TaxOffice"
lazy="false"
update="false"
insert="false"
column="TAX_OFFICE_ID"/>
the message from hibarnate disappears but the column on TAX_OFFICE_ID on table BUSSINESS is always null and
object never assosiated.
How can i have the many-to-one assosiation with the ability an object of Bussiness same times have a TaxOffice and sometimes not?