3 Replies Latest reply on Apr 6, 2007 10:38 AM by fhh

    How to insert a timestamp to a Not Nullable column from a fo

    Alex Narinsky Newbie

      I have a class that contains a Date property - timestamp. Also, I have a form for persisting this object in the database. This form was created by the seam generator. In the database the timestamp is not nullable.

      The timestamp should be equal to a current time. A user should not insert it. So I removed this field from the form and changed the setter for this property

      public void setTimestamp(Date time) {
      if (time==null)
      {
      timestamp = new Date();
      }
      this.timestamp = time;
      }

      However, the persisting mechanism does not use this setter. As a result I am getting the exception:
      Exception during request processing: javax.servlet.ServletException: #{projNotesHome.persist}: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: : com.scea.spot4.ProjNotes.timestamp

      Any suggestion?

        • 1. Re: How to insert a timestamp to a Not Nullable column from
          fhh Expert

          The setter is never called if you don't set the value on the jsf page.

          To achieve what you want either use a default on the column value by changing the created database schema or use the @Prepersist annotation.

          Regards

          Felix

          • 2. Re: How to insert a timestamp to a Not Nullable column from
            Alex Narinsky Newbie

            Thank you, great. Prepersist did help.

            Still, with above scenario I have the problem with id. It supposed to be auto generated. However, when I add @GeneratedValue I am getting the exception on startup:
            ObjectName: persistence.units:ear=spot4.ear,unitName=spot4
            State: FAILED
            Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: Missing sequence or table: hibernate_sequence
            I Depend On:
            jboss.jca:service=DataSourceBinding,name=spot4Datasource

            With the old variant of Hibernate this auto sequence generated worked with the following annotation used in Doclet:
            /**
            * @hibernate.id column="ID" generator-class="increment" unsaved-value="0"
            */
            Again, any suggestions?

            • 3. Re: How to insert a timestamp to a Not Nullable column from
              fhh Expert

              I think it is not a good idea to use the generator strategy increment.

              Create the sequence insted. If you have already data in the schema, set the initial value of the sequence so you don't get duplicate pks.

              Use @SequenceGenerator or alter the sequence manually.

              Regards

              Felix