Hibernate version:
2.1.7c
Mapping documents:
<?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="edu.ucdavis.mediaworks.petstore.Cat" table="CAT">
<id name="id" type="long" column="CAT_ID">
<generator class="sequence">
<param name="sequence">cat_id_seq</param>
</generator>
</id>
<property name="name" type="string" length="16" not-null="true">
<column name="name"/>
</property>
<property name="sex" type="character">
<column name="sex"/>
</property>
<property name="weight" type="float">
<column name="weight"/>
</property>
<many-to-one name="owner" column="owner" class="edu.ucdavis.mediaworks.petstore.Person" not-null="true"/>
</class>
</hibernate-mapping>
<?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="edu.ucdavis.mediaworks.petstore.Person" table="PERSON">
<id name="id" type="long" column="PERSON_ID">
<generator class="sequence">
<param name="sequence">person_id_seq</param>
</generator>
</id>
<property name="firstName" type="string" length="80" not-null="true">
<column name="first_name"/>
</property>
<property name="middleName" type="string" length="80">
<column name="middle_name"/>
</property>
<property name="lastName" type="string" length="80" not-null="true">
<column name="last_name"/>
</property>
<property name="email" type="string" length="80">
<column name="email"/>
</property>
<property name="role" type="short">
<column name="role"/>
</property>
<set name="cats" lazy="true" inverse="true" cascade="save-update">
<key column="owner"/>
<one-to-many class="edu.ucdavis.mediaworks.petstore.Cat"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
tx = session.beginTransaction();
Person thomas = new Person();
thomas.setFirstName("Thomas");
thomas.setMiddleName("P");
thomas.setLastName("Amsler");
thomas.setEmail("tpamsler@ucdavis.edu");
thomas.setRole((short)1);
Cat princess = new Cat();
princess.setName("Princess");
princess.setSex('F');
princess.setWeight(7.4f);
thomas.addCat(princess);
princess.setOwner(thomas);
session.save(thomas);
session.save(princess);
tx.commit();
Full stack trace of any exception that occurs:
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: edu.ucdavis.mediaworks.petstore.Cat.owner
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1286)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:937)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:866)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:788)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
at edu.ucdavis.mediaworks.petstore.MainServlet.tester(Unknown Source)
at edu.ucdavis.mediaworks.petstore.MainServlet.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Name and version of the database you are using:
PostgreSQL v7.4.6
The generated SQL (show_sql=true):
--- Person Table
CREATE TABLE Person (
person_id bigint primary key,
first_name varchar(80),
middle_name varchar(80),
last_name varchar(80),
email varchar(80),
role smallint
);
--- Cat Table
CREATE TABLE Cat (
cat_id bigint primary key,
name varchar(16) not null,
sex character(1),
weight real,
owner bigint references Person
);
--- Sequences for primary keys
create sequence person_id_seq;
create sequence cat_id_seq;
Debug level Hibernate log excerpt:
INFO
|