In my SQL Server 2000 database, I have a timestamp label (in a function not in a data type) of type DATETIME named lastTouched , set to getdate() as the default value / binding.
I use JPA entity classes created with Netbeans 6.5 and have this in my code
@Basic(optional = false) @Column(name = "LastTouched") @Temporal(TemporalType.TIMESTAMP) private Date lastTouched;
However, when I try to put an object in the database, I get
javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.generic.Stuff.lastTouched
I tried setting the @Basic parameter to (optional = true) , but this throws an exception because the database does not allow null values for the TIMESTAMP column, which is not by design.
ERROR JDBCExceptionReporter - Cannot insert the value NULL into column 'LastTouched', table 'DatabaseName.dbo.Stuff'; column does not allow nulls. INSERT fails.
I used to get this to work in pure Hibernate, but I have the point of switching to JPA and don’t know how to say that this column is supposed to be generated on the database side. Note that I am still using Hibernate as the persistence level of JPA.
java timestamp annotations jpa persistence
James McMahon May 01 '09 at 3:20 p.m. 2009-05-01 15:20
source share