-->
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: Why the is the value resetted to null in my POJO ?
PostPosted: Wed Apr 06, 2005 4:47 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2005 4:56 pm 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
You have best chances of getting reply if your question is summarized in few lines. Noone has time to read all the stack traces even thought you have provided it for completeness.

Try cut and paste and post only most relevant information.

Ron


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2005 4:34 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
rrr123 wrote:
You have best chances of getting reply if your question is summarized in few lines. Noone has time to read all the stack traces even thought you have provided it for completeness.

Try cut and paste and post only most relevant information.

Ron


Thank you, maybe in the future I will get more answers ;-)

Here my question in short mode.

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".

I discovered that my affiliationDate setter is called between the "john.setAffiliationDate( new Date() )" and "dao.makePersistent( john )" to set a null value, but why ?

Thank you
Lilian


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.