Hibernate version:
3.0
Mapping documents:
Worker.hbm.xml
-------------------
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<joined-subclass
name="bab.admin.model.persistent.Worker"
table="t_worker"
extends="bab.admin.model.persistent.IParty" >
<key column="partyId" />
<property name="enabled" type="java.lang.Boolean" update="true"
insert="true" access="property" column="enabledYN" not-null="false"
unique="false" />
<property name="critic" type="java.lang.String" update="true"
insert="true" access="property" column="critic" not-null="false"
unique="false" />
<property name="compliment" type="java.lang.String"
update="true" insert="true" access="property" column="compliment"
not-null="false" unique="false" />
<property name="motivationCode" type="java.lang.String"
update="true" insert="true" access="property" column="motivationCode"
not-null="true" unique="false" />
<property name="motivationShortCode" type="java.lang.String"
update="true" insert="true" access="property"
column="motivationShortCode" not-null="true" unique="false" />
<property name="affiliationDate" type="java.util.Date"
update="true" insert="true" access="property"
column="affiliationDate" not-null="true" unique="false" />
<property name="lastReactivationDate" type="java.util.Date"
update="true" insert="true" access="property"
column="lastReactivationDate" not-null="false" unique="false" />
<property name="workPermitCode" type="java.lang.String"
update="true" insert="true" access="property" column="workPermitCode"
not-null="true" unique="false" />
<property name="authorizationExpirationDate"
type="java.util.Date" update="true" insert="true" access="property"
column="authorizationExpirationDate" not-null="false" unique="false" />
<property name="source" type="java.lang.Boolean" update="true"
insert="true" access="property" column="sourceYN" not-null="false"
unique="false" />
<set name="specialities" table="t_workerspeciality" lazy="true"
inverse="true" cascade="save-update" sort="unsorted">
<key column="partyId"></key>
<many-to-many class="bab.admin.model.persistent.Speciality"
column="specialityId" outer-join="auto" />
</set>
<one-to-one name="avs" class="bab.admin.model.persistent.AVS"
cascade="none" outer-join="auto" constrained="false" />
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Worker.xml
containing the additional properties and place it in your merge dir.
-->
</joined-subclass>
</hibernate-mapping>
IParty.hbm.xml :
--------------------
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="bab.admin.model.persistent.IParty" table="t_party"
dynamic-update="false" dynamic-insert="false"
select-before-update="false" optimistic-lock="version">
<id name="id" column="partyId" type="java.lang.Integer">
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-IParty.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator column="partyType" />
<property name="partyType" column="partyType" />
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-IParty.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
WorkerDAO.makePersistent( Worker worker ):Code:
public void makePersistent( Worker worker ) throws InfrastructureException
{
try
{
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
System.out.println( worker.getAffiliationDate() );
session.save( worker );
tx.commit();
HibernateUtil.closeSession();
}
catch ( HibernateException ex )
{
throw new InfrastructureException( ex );
}
}
WorkerDAOTests.testMakePersistent:Code:
WorkerDAO dao = new WorkerDAO();
Worker john = new Worker();
john.setAffiliationDate( new Date() );
john.setWorkPermitCode( "worker.permit.ch" );
try
{
System.out.println( "--" +john.getAffiliationDate() );
dao.makePersistent( john );
System.out.println( "++" +john.getAffiliationDate() );
}
catch ( Exception e )
{
System.out.println( "_1_" +e.getCause() );
System.out.println( "_2_" +e.getMessage() );
System.out.println( "_3_" +e );
e.printStackTrace();
System.out.println( "**" +john.getAffiliationDate() );
}
Worker.setAffiliationDate( Date date ):Code:
public void setAffiliationDate( Date date )
{
if ( date == null )
{
System.out.println( "setAffiliationDate( NULL )" );
System.out.println( "==========================" );
try
{
Object o = null;
o.getClass();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
this.affiliationDate = date;
}
Full stack trace of any exception that occurs:--Wed Apr 06 10:26:10 CEST 2005
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
setAffiliationDate( NULL )
==========================
java.lang.NullPointerException
at bab.admin.model.persistent.Worker.setAffiliationDate(Worker.java:340)
at bab.admin.model.persistent.Worker$$BulkBeanByCGLIB$$26e2474b.setPropertyValues(<generated>)
at org.hibernate.util.ReflectHelper.getBulkBean(ReflectHelper.java:179)
at org.hibernate.tuple.PojoTuplizer.<init>(PojoTuplizer.java:83)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:47)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:212)
at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:400)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:87)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1054)
at author_work.HibernateUtil.<clinit>(HibernateUtil.java:16)
at bab.admin.model.dao.WorkerDAO.makePersistent(WorkerDAO.java:93)
at bab.admin.model.dao.WorkerDAOTests.testMakePersistent(WorkerDAOTests.java:44)
at bab.admin.model.dao.WorkerDAOTests.main(WorkerDAOTests.java:22)
Wed Apr 06 10:26:10 CEST 2005
Hibernate: insert into t_party (partyType) values (?)
Hibernate: insert into t_worker (enabledYN, critic, compliment, motivationCode, motivationShortCode, affiliationDate, lastReactivationDate, workPermitCode, authorizationExpirationDate, sourceYN, partyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
_1_org.hibernate.PropertyValueException: not-null property references a null or transient value: bab.admin.model.persistent.Worker.affiliationDate
_2_org.hibernate.PropertyValueException: not-null property references a null or transient value: bab.admin.model.persistent.Worker.affiliationDate
_3_bab.admin.model.exceptions.InfrastructureException: org.hibernate.PropertyValueException: not-null property references a null or transient value: bab.admin.model.persistent.Worker.affiliationDate
bab.admin.model.exceptions.InfrastructureException: org.hibernate.PropertyValueException: not-null property references a null or transient value: bab.admin.model.persistent.Worker.affiliationDate
at bab.admin.model.dao.WorkerDAO.makePersistent(WorkerDAO.java:103)
at bab.admin.model.dao.WorkerDAOTests.testMakePersistent(WorkerDAOTests.java:44)
at bab.admin.model.dao.WorkerDAOTests.main(WorkerDAOTests.java:22)
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: bab.admin.model.persistent.Worker.affiliationDate
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:163)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)**null
at bab.admin.model.dao.WorkerDAO.makePersistent(WorkerDAO.java:98)
... 2 more
Name and version of the database you are using:MySQL 4.1
The generated SQL (show_sql=true):insert into t_party (partyType) values (?)
insert into t_worker (enabledYN, critic, compliment, motivationCode, motivationShortCode, affiliationDate, lastReactivationDate, workPermitCode, authorizationExpirationDate, sourceYN, partyId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hi,
I cant understand this behavior... I am trying to make a Worker persistent. So, I do the following :
Code:
WorkerDAO dao = new WorkerDAO();
Worker john = new Worker();
john.setAffiliationDate( new Date() );
john.setWorkPermitCode( "worker.permit.ch" );
dao.makePersistent( john );
and I get "bab.admin.model.exceptions.InfrastructureException: org.hibernate.PropertyValueException: not-null property references a null or transient value: bab.admin.model.persistent.Worker.affiliationDate".
So, I added this to my affiliationDate setter :
Code:
if ( date == null )
{
System.out.println( "setAffiliationDate( NULL )" );
System.out.println( "==========================" );
try
{
Object o = null;
o.getClass();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
to know who put a null value after I put the current date :
Code:
setAffiliationDate( NULL )
==========================
java.lang.NullPointerException
at bab.admin.model.persistent.Worker.setAffiliationDate(Worker.java:340)
at bab.admin.model.persistent.Worker$$BulkBeanByCGLIB$$26e2474b.setPropertyValues(<generated>)
at org.hibernate.util.ReflectHelper.getBulkBean(ReflectHelper.java:179)
at org.hibernate.tuple.PojoTuplizer.<init>(PojoTuplizer.java:83)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:47)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:212)
at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:400)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:87)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1054)
at author_work.HibernateUtil.<clinit>(HibernateUtil.java:16)
at bab.admin.model.dao.WorkerDAO.makePersistent(WorkerDAO.java:93)
at bab.admin.model.dao.WorkerDAOTests.testMakePersistent(WorkerDAOTests.java:44)
at bab.admin.model.dao.WorkerDAOTests.main(WorkerDAOTests.java:22)
Please help me tu understand this
Best regards
Lilian