-->
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: many-to-one associations with not-null="false" att
PostPosted: Wed Aug 10, 2005 8:14 am 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
Hi,
My question is, is it possible to have a many-to-one association with a not-null attribute to false.

Indeed hibernate return :

Quote:
not-null property references a null or transient value


when I want to save an Object with a property to null.

Quote:
<many-to-one name="currency2" column="MT940_F64_CURRENCY_ID" class="Currency" not-null="false"/>


The attibute not-null="false" seems to be ignored !!


Top
 Profile  
 
 Post subject: Re: many-to-one associations with not-null="false"
PostPosted: Wed Aug 10, 2005 9:03 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Saloucious wrote:
Hi,
My question is, is it possible to have a many-to-one association with a not-null attribute to false.

Indeed hibernate return :

Quote:
not-null property references a null or transient value


when I want to save an Object with a property to null.

Quote:
<many-to-one name="currency2" column="MT940_F64_CURRENCY_ID" class="Currency" not-null="false"/>


The attibute not-null="false" seems to be ignored !!



http://www.hibernate.org/ForumMailingli ... AskForHelp

Can you post your code, mapping files etc... This always works for me.

What about your database constraints ? This will only work if your database is also set to allow null values into the MT940_F64_CURRENCY_ID column.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 9:27 am 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
I work on a Oracle 9.2 database.
It accept the null value , because when I test it with a DBUnit, this work fine.
Here is my mapping

Quote:
<hibernate-mapping package="model">

<class name="Mt940" table="MT940">
<id name="idMt940" column="ID_MT940" type="java.lang.Long">
<generator class="increment"/>
</id>

<property name="mt940F20Sender" column="MT940_F20_SENDER" type="java.lang.String" />
<property name="mt940F21ReferenceMessage" column="MT940_F21_REFERENCE_MESSAGE" type="java.lang.String" />
<property name="mt940F25AccountId" column="MT940_F25_ACCOUNT_ID" type="java.lang.String" />
<property name="mt940F28cSequenceNumber" column="MT940_F28C_SEQUENCE_NUMBER" type="java.lang.String" />
<property name="mt940F28cStatementNumber" column="MT940_F28C_STATEMENT_NUMBER" type="java.lang.String" />
<property name="mt940F60Amount" column="MT940_F60_AMOUNT" type="java.lang.Float" />
<property name="mt940F60DcMark" column="MT940_F60_DC_MARK" type="java.lang.String" />
<property name="mt940F60OperationDate" column="MT940_F60_OPERATION_DATE" type="java.util.Date" />
<property name="mt940F60Option" column="MT940_F60_OPTION" type="java.lang.String" />
<property name="mt940F62Amount" column="MT940_F62_AMOUNT" type="java.lang.Float" />
<property name="mt940F62DcMark" column="MT940_F62_DC_MARK" type="java.lang.String" />
<property name="mt940F62OperationDate" column="MT940_F62_OPERATION_DATE" type="java.util.Date" />
<property name="mt940F62Option" column="MT940_F62_OPTION" type="java.lang.String" />
<property name="mt940F64Amount" column="MT940_F64_AMOUNT" type="java.lang.Float" />
<property name="mt940F64DcMark" column="MT940_F64_DC_MARK" type="java.lang.String" />
<property name="mt940F64OperationDate" column="MT940_F64_OPERATION_DATE" type="java.util.Date" />

<many-to-one name="account" column="ID_ACCOUNT" class="Account" not-null="true" />

<many-to-one name="currency" column="MT940_F60_CURRENCY_ID" class="Currency" not-null="true" />

<many-to-one name="currency1" column="MT940_F62_CURRENCY_ID" class="Currency" not-null="true" />

<many-to-one name="currency2" column="MT940_F64_CURRENCY_ID" class="Currency" not-null="false" />

<many-to-one name="mt940Brut" column="ID_MT940_BRUT" class="Mt940Brut" not-null="true" />

<set name="mt940ForwardBalanceSet" inverse="true">
<key column="ID_MT940"/>
<one-to-many class="Mt940ForwardBalance"/>
</set>

<set name="mt940TransactionSet" inverse="true">
<key column="ID_MT940"/>
<one-to-many class="Mt940Transaction"/>
</set>
</class>


The currency mapping is
Quote:
<hibernate-mapping package="model">

<class name="Currency" table="CURRENCY">
<id name="idCurrency" column="ID_CURRENCY" type="java.lang.Long">
<generator class="increment"/>
</id>

<property name="currencyName" column="CURRENCY_NAME" type="java.lang.String" />

<set name="accountSet" inverse="true">
<key column="ID_CURRENCY"/>
<one-to-many class="Account"/>
</set>

<set name="mt940Set" inverse="true">
<key column="MT940_F62_CURRENCY_ID"/>
<one-to-many class="Mt940"/>
</set>

<set name="mt9401Set" inverse="true">
<key column="MT940_F60_CURRENCY_ID"/>
<one-to-many class="Mt940"/>
</set>

<set name="mt9402Set" inverse="true">
<key column="MT940_F64_CURRENCY_ID"/>
<one-to-many class="Mt940"/>
</set>

<set name="mt940ForwardBalanceSet" inverse="true">
<key column="FORWARD_BALANCE_CURRENCY_ID"/>
<one-to-many class="Mt940ForwardBalance"/>
</set>
</class>

</hibernate-mapping>



In my code a just made something like that :
Code:
mt.setMt940F20Sender(m.getF20());
           
           mt.setMt940F21ReferenceMessage(m.getF21());
         
           mt.setMt940F28cSequenceNumber(m.getF28_sequence());
           mt.setMt940F28cStatementNumber(m.getF28_statement());
mt940Hib.saveMt940(mt);



And Hibernate retuns :

Code:
     [java] org.springframework.orm.hibernate3.HibernateSystemException: not-null property references a null or transient value: com.planaxis.swifter.model.Mt940.currency2; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.planaxis.swifter.model.Mt940.currency2
     [java] org.hibernate.PropertyValueException: not-null property references a null or transient value: com.planaxis.swifter.model.Mt940.currency2
     [java] at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
     [java] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:236)
     [java] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
     [java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
     [java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
     [java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
     [java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
     [java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
     [java] at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
     [java] at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)
     [java] at org.springframework.orm.hibernate3.HibernateTemplate$18.doInHibernate(HibernateTemplate.java:630)
     [java] at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:315)
     [java] at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:627)
     [java] at com.planaxis.swifter.dao.hibernate.Mt940DAOHibernate.saveMt940(Unknown Source)
     [java] at com.planaxis.swifter.front.Main.launch(Unknown Source)
     [java] at com.planaxis.swifter.front.Main.listCreated(Unknown Source)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 9:59 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
What version of Hibernate are you using ?

This works without problems for me using v3.0.5. If you're using a debugger, I would recommend setting a breakpoint in the Nullability.checkNullability() method and step through the code to see what's going wrong.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 11:05 am 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
Oh I'm mad!
My ant script pointed to a bad path !!!
I have modifing bad files !!!!!!

Sorry for the disturbing


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 11:06 am 
Newbie

Joined: Wed Aug 10, 2005 8:07 am
Posts: 14
Where is the button to give you a credit ?


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.