-->
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.  [ 2 posts ] 
Author Message
 Post subject: attempted to save null error
PostPosted: Thu Oct 09, 2003 2:58 pm 
Newbie

Joined: Tue Oct 07, 2003 9:43 am
Posts: 16
Location: Chicago
I have a simple one-to-one mapping between a Vendor (Parent) and a Contact (Child). When I try to save Vendor I get the following error:

Code:
4:30:27,094 DEBUG SessionImpl:656 - saving [com.demo.hb.Vendor#100062]
4:30:27,094 DEBUG Cascades:336 - processing cascades for: com.demo.hb.Vendor
4:30:27,104 DEBUG Cascades:344 - done processing cascades for: com.demo.hb.Vendor
4:30:27,114 DEBUG Cascades:336 - processing cascades for: com.demo.hb.Vendor
4:30:27,114 DEBUG Cascades:87 - cascading to saveOrUpdate()
4:30:27,114 DEBUG Cascades:237 - unsaved-value strategy NULL
4:30:27,114 DEBUG SessionImpl:1201 - saveOrUpdate() unsaved instance with id: null
4:30:27,124  WARN RequestProcessor:538 - Unhandled Exception thrown: class java.lang.NullPointerException
Oct 9, 2003 2:30:27 PM EDT> <Error> <HTTP> <BEA-101017> <[ServletContext(id=32225808,name=hb,context-path=)] Root cause of ServletException.
ava.lang.NullPointerException: attempted to save null
       at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:580)
       at net.sf.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:37)
       at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:599)
       at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1202)
       at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:88)
       at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:258)
       at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:341)
       at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:739)
       at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
       at com.demo.hb.BaseDAO.addVendor(BaseDAO.java:47)


Below are also my Vendor and Contact mappings:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.demo.hb.Vendor" table="HB_VENDOR">
        <id name="vendorId" column="VENDORID" unsaved-value="null">
           <generator class="sequence">
              <param name="sequence">seq_vendorid</param>
           </generator>
          </id>
        <property name="vendorName" column="VENDORNAME"/>
        <one-to-one name="contact" class="com.demo.hb.Contact" cascade="all"/>
    </class>
</hibernate-mapping>

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.demo.hb.Contact" table="HB_VENDOR_CONTACT">
       <id name="contactId" column="VENDORID" unsaved-value="null">
            <generator class="foreign">
               <param name="property">vendor</param>
            </generator>
        </id>
        <property name="contactCity" column="CITY"/>
        <property name="contactCountry" column="COUNTRY"/>
        <property name="contactFirstName" column="CONTACTFIRSTNAME"/>
        <property name="contactLastName" column="CONTACTLASTNAME"/>
        <property name="contactLine1" column="ADDRESSLINE1"/>
        <property name="contactLine2" column="ADDRESSLINE2"/>
        <property name="contactState" column="STATE"/>
        <property name="contactTitle" column="CONTACTTITLE"/>
        <property name="contactZip" column="ZIP"/>
      <one-to-one name="vendor" class="com.demo.hb.Vendor"/>
    </class>
</hibernate-mapping>


Please advise.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2003 3:07 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
I had the same thing happen to me when I did a 1-1-1-M mapping. The first 1-1 mapping works fine, but the second one fails - I have to have two as I'm working with legacy formatted XML. I tried a lot of things but just couldn't get it to work. So eventually I remove the cascade="all" option from the <one-to-one> tag in the parent (of the second 1-1), and did that bit manually - setting the child ID and saving it (if new).

I posted my mappings a while back, still waiting for see what exactly causes this not to work, i.e. throw this exact same exception.

Anyway, here is one of my one-to-one that works:

Code:
//Parent XML maps to Party:
<class name="cdl.impl.XMLImpl" table="XML">
    <id name="XMLID" column="XMLID" type ="java.lang.Long" unsaved-value="null">
        <generator class="identity"/>
    </id>
...
    <one-to-one name="Party" class="cdl.impl.PartyImpl" cascade="all"/>
...

Code:
//Child Party maps to XML:
<class name="cdl.impl.PartyImpl" table="Party">
    <id name="XMLID" column="XMLID" type ="java.lang.Long" unsaved-value="null">
        <generator class="foreign">
            <param name="property">XML</param>
        </generator>
    </id>
    <one-to-one name="XML" class="cdl.impl.XMLImpl" constrained="true"/>
...


-G


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