-->
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.  [ 4 posts ] 
Author Message
 Post subject: one-to-many problems
PostPosted: Wed Jul 28, 2004 10:13 am 
Newbie

Joined: Thu Jun 17, 2004 1:09 pm
Posts: 9
In attempt to change my code to follow recommendations in the reference document I am getting the following error:

Code:
Try to insert null into a non-nullable column: column: CAMPAIGN_ID table: EDITION in statement [insert into EDITION (TITLE, EMAIL_SUBJECT, MAIN_TEXT, TRACKABLE_LINK, LAYOUT, EDITION_ID) values (?, ?, ?, ?, ?, null)]>

2004-07-28 09:59:11,113 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] - <could not insert: [com.fp.eMarketing.dataModels.Edition]>



I know I'm missing one keyword somewhere in my HBM file, I'm just not sure where.

My edition HBM is as follows:

Code:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
               "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


<hibernate-mapping>

  <class name="com.fp.eMarketing.dataModels.Edition" table="EDITION">

    <id name="editionID" type="int" column="EDITION_ID" unsaved-value="0">
      <meta attribute="scope-set">protected</meta>
      <generator class="native"/>
    </id>

    <property name="title" type="string">
       <column name="TITLE" not-null="true" unique="true" index="TITLE_IDX"/>
    </property>

    <property name="emailSubject" type="string">
       <column name="EMAIL_SUBJECT" not-null="true"/>
    </property>

    <property name="mainText" type="text">
       <column name="MAIN_TEXT" not-null="true"/>
    </property>

    <property name="includeTrackableLink" type="boolean">
       <column name="TRACKABLE_LINK" not-null="true"/>
    </property>

    <property name="layout" type="int">
       <column name="LAYOUT" not-null="true"/>
    </property>

   <one-to-one name="campaigns" class="com.fp.eMarketing.dataModels.Campaign"
           foreign-key="CAMPAIGN_FK"/>




  </class>


</hibernate-mapping>



and my campaign hbm is as follows:

Code:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
               "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

  <class name="com.fp.eMarketing.dataModels.Campaign" table="CAMPAIGN">

    <id name="campaignID" type="int" column="CAMPAIGN_ID"  unsaved-value="0">
      <meta attribute="scope-set">protected</meta>
      <generator class="native"/>
    </id>

    <property name="title" type="string">
       <column name="TITLE" not-null="true" unique="true" index="TITLE_IDX"/>
    </property>

    <property name="type" type="int">
       <column name="TYPE" not-null="true" unique="false"/>
    </property>

    <property name="contactName" type="string">
       <column name="CONTACT_NAME" not-null="true"/>
    </property>

    <property name="contactEmail" type="string">
       <column name="CONTACT_EMAIL" not-null="true"/>
    </property>

    <property name="administrationEmail" type="string">
       <column name="ADMIN_EMAIL" not-null="true"/>
    </property>

    <property name="postAddress1" type="string">
       <column name="POST_ADDRESS1" not-null="true"/>
    </property>

    <property name="postAddress2" type="string">
       <column name="POST_ADDRESS2" not-null="true"/>
    </property>

    <set name="editions" table="CAMPAIGN_EDITIONS" inverse="true" cascade="all-delete-orphan">
      <key column="CAMPAIGN_ID"/>
      <one-to-many class="com.fp.eMarketing.dataModels.Edition"/>
    </set>
   
  </class>

<query name="com.fp.eMarketing.retrieveAllCampaigns">
<![CDATA[
   from com.fp.eMarketing.dataModels.Campaign as c
]]>
</query>


</hibernate-mapping>




Campaign is the parent and Edition is the child.

Before I just had the one-to-many in Campaign and this was fine for saving data, but it did not do a retrieval. After filtering through the documents it seemed I had to set up the additional relationship and this is when the save stopped working.

Any help would be great.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 4:07 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Shouldn't you be mapping the Edition side of the mapping as a many-to-one?

The example of this bidirectional mapping is found at http://www.hibernate.org/hib_docs/reference/en/html_single/#example-parentchild-bidir


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 4:09 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
I should add that once you've set it up correctly as a bidirectional relationship, you won't need to have the cascade set to all-delete-orphan on the Campaign object, you can just set it to all. Will your Campaign's always be saved before your Edition objects, because you currently only have the relationship cascading in one direction?

Also, what do you mean by the statement "but it did not do a retrieval"?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 29, 2004 2:30 pm 
Newbie

Joined: Thu Jun 17, 2004 1:09 pm
Posts: 9
In the code above, when I retrieve a Campaign, the Editions in that campaign are not included in the retrieval.

I made the following change to Edition:

Code:
   <many-to-one name="campaign" column="CAMPAIGN_ID"  cascade="all"
        class="com.fp.eMarketing.dataModels.Campaign" not-null="true" />



and the following to Campaign

Code:
    <set name="editions" table="CAMPAIGN_EDITIONS" inverse="true" cascade="all-delete-orphan">
      <key column="CAMPAIGN_ID"/>
      <one-to-many class="com.fp.eMarketing.dataModels.Edition"/>
    </set>



which now gives the exception:

Code:
not-null property references a null or transient value: com.fp.eMarketing.dataModels.Edition.campaign


Time to get the Manning book!


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