# PropertyValueException when trying to persist a new object

**URL:** <https://discourse.hibernate.org/t/propertyvalueexception-when-trying-to-persist-a-new-object/5298>\
**Category:** Hibernate ORM\
**Created:** [April 27, 2021, 2:34pm UTC](https://discourse.hibernate.org/t/propertyvalueexception-when-trying-to-persist-a-new-object/5298 "2021-04-27T14:34:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![999cm999](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/999cm999/32/1503_2.png) [@999cm999](https://discourse.hibernate.org/u/999cm999)\
**Post date:** [April 27, 2021, 2:34pm UTC](https://discourse.hibernate.org/t/propertyvalueexception-when-trying-to-persist-a-new-object/5298/1 "2021-04-27T14:34:26Z")

</div>

Hi,

I am getting this persistent error that I can’t fix:

> PropertyValueException: not-null property references a null or transient value AstroLab.Research.LearningLab.AstroComet.\_AstroLab.Research.LearningLab.AstroSystem.CometsBackref

This error happens inside Session.Save. I create a new comet programatically, and I am trying to use Session.Save to persist it to the database.

Googling the error turns up very little info.

In the database, the two tables look like this:

```auto

CREATE TABLE cometList (
	[systemID] [int] NOT NULL,
	[cometID] [int] IDENTITY(1,1) NOT NULL,
	[cometName] [nvarchar](255) NOT NULL,
	[cometSequence] [int] NOT NULL,
	[isLocal] [bit] NULL
);
CREATE TABLE systemList (
	[learningID] [int] NOT NULL,
	[systemID] [int] IDENTITY(1,1) NOT NULL,
	[systemSequence] [int] NOT NULL,
	[systemName] [nvarchar](255) NULL,
	[systemDateTime] [datetime2](0) NULL,
);

```

In the cometList table, the systemID column is a foreign key(systemList).

Inside my .NetCore Web App, my AstroComet XML mapping looks like this:

```auto
<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    schema="dbo" assembly="AstroLab.Learn" namespace="AstroLab.Research.LearningLab">
  <class name="AstroComet" table="cometList">
    <id name="Id" column="cometID">
      <generator class="identity" />
    </id>

    <many-to-one name="System" class="AstroSystem" column="systemID" update="false" insert="false" />
    <property name="Sequence" column="cometSequence" update="false" insert="false" />

    <property name="Title" column="cometName" />

    <property name="IsLocal" column="isLocal"/>

  </class>
</hibernate-mapping>

```

And the AstroSystem mapping looks like this:

```auto
<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    schema="dbo" assembly="AstroLab.Learn" namespace="AstroLab.Research.LearningLab">

  <class name="AstroSystem" table="systemList">
    <id name="Id" column="systemID">
      <generator class="identity" />
    </id>

    <many-to-one name="LearningLab" class="LearningLab" column="learningID" insert="false" update="false" />
    <property name="Sequence" column="systemSequence" insert="false" update="false"/>

    <property name="Title" column="systemName" />
    <property name="ResearchDate" column="systemDateTime" />

    <list name="Comets" inverse="false" cascade="all">
      <key column="systemID" not-null="true" />
      <index column="cometSequence" />
      <one-to-many class="AstroComet" />
    </list>

  </class>
</hibernate-mapping>

```

I’ve searched, tried a few things, rewrote some of the code, but it always gives me this error no matter how I try to fix it.

If anyone has any experience with an error like this, please let me know.

Thanks!

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [April 28, 2021, 8:40am UTC](https://discourse.hibernate.org/t/propertyvalueexception-when-trying-to-persist-a-new-object/5298/2 "2021-04-28T08:40:10Z")

</div>

This forum is for Hibernate, the Java implementation. For questions about NHibernate, please use the forums as listed on the [https://nhibernate.info](https://nhibernate.info) website like e.g. [https://groups.google.com/g/nhusers](https://groups.google.com/g/nhusers)
