session.save (p1);
           Idcard idcard=new Idcard();
            idcard.setValidate(new Date());
            idcard.setPerson(p1);
           试试这样呢!
p1是临时状态,要先持久化吧!

解决方案 »

  1.   

    用级联呀..Person p1=new Person();
                p1.setId(2);
                p1.setName("scott1");
                 
                Idcard idcard=new Idcard();
                idcard.setValidate(new Date());
                idcard.setPerson(p1);         
                session.save(idcard);<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
        <class name="com.xyy.domain.Idcard">
            <id name="id" type="java.lang.Integer">
                <column name="ID" />
                <generator class="foreign">
                    <param name="property">person</param>
                </generator>
            </id>
            <property name="validate" type="java.util.Date">
                <column name="validate"/>
            </property>
            <!-- 配置one-to-one
            constrained:不配置,则不会自动生成外键列,配置了,则会生成外键列
             -->
            <one-to-one name="person" constrained="true" cascade="save-update"/>
        </class>
    </hibernate-mapping>
      

  2.   

    加上级联操作就行了
    cascade=save-update
      

  3.   

    楼上回答的统统都是扯淡,都不对。
    这个问题我解决了
    楼主在Idcard.hbm.xml文件中有这样一行配置:
    <property name="validate" type="java.util.Date">
         <column name="validate"/>
    </property>
    其中validate是一个关键字,将validate改成其他的就可以了,比如什么validate1之类的。
      

  4.   


    楼主在Idcard.hbm.xml文件中有这样一行配置:
    <property name="validate" type="java.util.Date">
         <column name="validate"/>
    </property>
    其中validate是一个关键字,将validate改成其他的就可以了,比如什么validate1之类的。
    太有用了