Maybe I'm totally wrong getting the problem but:
This is entity mapping, with property set to be autogenerated only on entity insertion into database.
Code:
@Entity()
@org.hibernate.annotations.Entity(selectBeforeUpdate=true)
public class Blog {
@Column(
columnDefinition="Timestamp",
insertable=false,
updatable=false
)
@org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.INSERT)
private Date dateAdded;
//no setter method for dateAdded property
And in the DAO code I have:
Code:
Blog blog = entityManager.find(Blog.class, new Long(10));
blog.setText("test2");
entityManager.persist(blog);
or
Code:
Query q = entityManager.createQuery("update Blog blog set blog.title = :newTitle");
q.setParameter("newTitle", "NewBlog222");
q.executeUpdate();
In both cases my dateAdded property gets updated!?
Why?