-->
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: one-to-one mapping problem
PostPosted: Tue Jan 27, 2004 11:55 am 
hi all,
i would like make the relation between AuctionItem and HomeInsurance, but it causes the error as following when i save the HomeInsurance object into database, anybody know what's wrong with it or my design have any problems, thanks :
ERROR code:
Code:
java.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 com.twofi.auction.implementations.HomeInsuranceControlBeanImpl.createNewAuctionItem(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.springframework.aop.framework.InvokerInterceptor.invoke(InvokerInterceptor.java:54)
   at org.springframework.aop.framework.MethodInvocationImpl.proceed(MethodInvocationImpl.java:216)
   at org.springframework.aop.framework.AopProxy.invoke(AopProxy.java:102)
   at $Proxy1.createNewAuctionItem(Unknown Source)
   at com.twofi.auction.actions.CreateHomeInsuranceAction.doExecute(Unknown Source)
   at webwork.action.ActionSupport.execute(ActionSupport.java:151)
   at webwork.dispatcher.GenericDispatcher.executeAction(GenericDispatcher.java:131)
   at webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:174)


HomeInsurance.java
Code:
public class HomeInsurance {
   private int auctionid;
   private AuctionItem auctionitem;


AuctionItem.java
Code:
public class AuctionItem {
   private int auctionid;


AuctionItem.hbm.xml:
Code:
<hibernate-mapping>
   <class name="com.twofi.auction.objects.AuctionItem" table="auctionitem">
      <id name="auctionid" type="long" column="auctionid" unsaved-value="any">
         <generator class="increment" />
      </id>
      <property name="userid" type="int" column="userid" />
      <property name="createdate" type="timestamp" column="createdate" />
      <property name="starttime" type="timestamp" column="starttime" />
      <property name="endtime" type="timestamp" column="endtime" />
      <property name="lengthtime" type="int" column="lengthtime" />
      <property name="startprice" type="double" column="startprice" />
      <property name="reservateprice" type="double" column="reservateprice" />
      <property name="incrementprice" type="double" column="incrementprice" />
      <property name="winneruserid" type="int" column="winneruserid" />
      <property name="status" type="string" column="status" />
      <property name="autopostpone" type="true_false" column="autopostpone" />
      <property name="repost" type="short" column="repost" />
      <property name="repostcount" type="short" column="repostcount" />
   </class>
</hibernate-mapping>


HomeInsurance.hbm.xml:
Code:
<hibernate-mapping>
    <class name="com.twofi.auction.objects.HomeInsurance" table="homeinsurance">
      <id name="auctionid" type="long" column="auctionid" unsaved-value="any">
         <generator class="foreign">
            <param name="property">auctionitem</param>
         </generator>
      </id>
      <one-to-one name="auctionitem" class="com.twofi.auction.objects.AuctionItem" cascade="all" constrained="true" />
        <property name="proposername" type="string" column="proposername"/>
        <property name="idcardno" type="string" column="idcardno"/>
        <property name="contactno" type="string" column="contactno"/>
        <property name="contactaddress" type="string" column="contactaddress"/>
        <property name="insureaddress" type="string" column="insureaddress"/>
        <property name="area" type="double" column="area"/>
      <property name="ageofbuilding" type="int" column="ageofbuilding" />
        <property name="endinsurance" type="date" column="endinsurance"/>
        <property name="startinsurance" type="date" column="startinsurance"/>
   </class>
</hibernate-mapping>


I have read on the documentation about
<generator class="foreign"> , but i am not very understand on it.

Tables of the auctionitem and homeinsurance:
Code:
auctionitem
============
auctionid
userid
createdate
starttime
lengthtime
startprice
reservateprice
incrementprice
winneruserid
status
autopostpone
repost
repostcount

homeinsurance
==============
auctionid
proposername
idcardno
contactno
contactaddress
insureaddress
area
ageofbuilding
startinsurance
endinsurance


Top
  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 7:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the code between the session open and close.
I suspect you don't properly setAuctionitem in the home object you save

_________________
Emmanuel


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.