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.