apache / apache/grails-core

Auto timestamp violations with multiple datasources

Open
#14,437 1 comment 0 reactions 1 assignee Claimed by @puneetbehl View on GitHub
relates-to: grails-data-hibernate5
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

# Background
Adding automatic timestamp properties (dateCreated and lastUpdated) into existing Micronaut applications with multiple data sources is causing violation exceptions when attempting to save any domain class.

Alternate attempts to use event handlers (beforeInsert, beforeUpdate) did not resolve the issue and did not appear to be called.

# Steps to reproduce
1. Setup an application with multiple data sources and domain classes that have auto timestamp properties
2. Save domain class

# Expected behaviour
Instance can be saved with `dateCreated` and `lastUpdated` values automatically set

# Actual behaviour
Attempts to save instance causes violation exceptions due to `dateCreated` value being null

```
Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column "DATE_CREATED"; SQL statement:
insert into time_test (id, version, date_created, last_updated, description) values (null, ?, ?, ?, ?) [23502-199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:457)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.table.Column.validateConvertUpdateSequence(Column.java:418)
at org.h2.table.Table.validateConvertUpdateSequence(Table.java:824)
at org.h2.command.dml.Insert.insertRows(Insert.java:175)
```

# Environment Information
Operating System: Ubuntu 18.04.3 LTS
GORM Version: 7.0.3.RELEASE
Grails Version (if using Grails): N/A
JDK Version: Java 8

# Example Application
A Micronaut application with multiple datasources and simple endpoint that saves domain class instance.

https://github.com/nmkae/mn-auto-ts

# Related Issues
Unclear if this is a Micronaut, hibernate or GORM issue.

Suggested solution in the Micronaut issue is not suitable, as the applications need to support multiple datasources.
https://github.com/micronaut-projects/micronaut-core/issues/1014

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.