-->
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.  [ 3 posts ] 
Author Message
 Post subject: net.sf.hibernate.PropertyValueException: not-null property
PostPosted: Mon Jan 10, 2005 7:39 pm 
Newbie

Joined: Wed Jul 07, 2004 1:23 pm
Posts: 3
Location: USA, California
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 8:27 pm 
Newbie

Joined: Wed Jul 07, 2004 1:23 pm
Posts: 3
Location: USA, California
I did some more test by just persisting a Person object and that works. I also Persisted the person object and then retrieved it and tried to add it with setOwner() but I still get the same error message saying that the owner reference in in the cat object is a "not-null property references a null or transient value". I read very carefully through the FAQ as well as the "Hibernate In Action" and "Hibernate A J2ee Developer's Guide" books and cannot see/find any thing different from my example to the ones that are listed there. I will keep trying to figure this one out. Any help is greatly appreciated.
Thank you very much.
Best,
--Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:39 pm 
Newbie

Joined: Wed Jul 07, 2004 1:23 pm
Posts: 3
Location: USA, California
Just to conclude this post, I found the error, actually USER error. The error was that I made a typo in the Cat bean where I misspelled owner in the setOwner method.


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