# Do NOT populate @UpdateTimestamp field when entity gets created

**URL:** <https://discourse.hibernate.org/t/do-not-populate-updatetimestamp-field-when-entity-gets-created/2613>\
**Category:** Hibernate ORM\
**Created:** [April 15, 2019, 9:31pm UTC](https://discourse.hibernate.org/t/do-not-populate-updatetimestamp-field-when-entity-gets-created/2613 "2019-04-15T21:31:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adorogensky](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/adorogensky/32/566_2.png) [@adorogensky](https://discourse.hibernate.org/u/adorogensky)\
**Post date:** [April 15, 2019, 9:31pm UTC](https://discourse.hibernate.org/t/do-not-populate-updatetimestamp-field-when-entity-gets-created/2613/1 "2019-04-15T21:31:09Z")

</div>

Is there a way to configure an @UpdateTimestamp field so it won’t get populated when the entity gets created but only when the entity gets updated?

Here is what I’m doing in this addUser operation,

```auto
@Entity
@Table(schema = "alpha", name = "user_profile")
public class User {

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id_sequence_generator")
	@SequenceGenerator(name = "user_id_sequence_generator", schema = "alpha", allocationSize = 1, sequenceName = "user_id_seq")
	private Integer id;

	private String login;

	private String password;

	@CreationTimestamp
	private LocalDateTime created;

	@UpdateTimestamp
	private LocalDateTime modified;

```

```auto
		User newUser = new User();
		newUser.setLogin(addUserInput.getLogin());
		newUser.setPassword(md5DigestAsHex(addUserInput.getPassword().getBytes()));

		userRepository.save(newUser);
		entityManager.flush();

		UserOutputTO addUserOutput = new UserOutputTO();
		addUserOutput.setId(newUser.getId());
		addUserOutput.setLogin(addUserInput.getLogin());
		addUserOutput.setCreated(newUser.getCreated());
		addUserOutput.setModified(newUser.getModified());

		return addUserOutput;

```

---

<div class="post-metadata">

**Author:** ![adorogensky](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/adorogensky/32/566_2.png) [@adorogensky](https://discourse.hibernate.org/u/adorogensky)\
**Post date:** [April 24, 2019, 5:16pm UTC](https://discourse.hibernate.org/t/do-not-populate-updatetimestamp-field-when-entity-gets-created/2613/2 "2019-04-24T17:16:32Z")

</div>

Does anyone have an idea?

---

<div class="post-metadata">

**Author:** ![Naros](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/naros/32/19_2.png) [@Naros](https://discourse.hibernate.org/u/Naros)\
**Post date:** [May 2, 2019, 6:59pm UTC](https://discourse.hibernate.org/t/do-not-populate-updatetimestamp-field-when-entity-gets-created/2613/3 "2019-05-02T18:59:35Z")

</div>

> [@adorogensky](#):
>
> Is there a way to configure an @UpdateTimestamp field so it won’t get populated when the entity gets created but only when the entity gets updated?

The reason that happens is because Hibernate only supports 3 modes of `GenerationTiming`

1. NEVER - No value is generated at insert or update.
2. INSERT - Value is only generated at insert.
3. ALWAYS - Value is generated at insert and update.

For the `@UpdateTimetamp` annotation, it uses the `ALWAYS` mode, which is why you are seeing the behavior you do where it gets set both on insert and update.

One idea might be to explicitly mark the column as not-insertable and see whether that is sufficient enough to avoid the column being included in the insert statements.

```auto
@Column(insertable=false)
@UpdateTimestamp
private LocalDateTime modified;

```
