JetBrains / JetBrains/Exposed

Entity created with default timestamp is null

Open
#2,412 4 comments 0 reactions 1 assignee Claimed by @obabichevjb View on GitHub
Dominant language
Kotlin
Stars
9.3k
Forks
798
Avg merge
4d 2h
Merged PRs (30d)
26

Description

I have the following table:
```kotlin
object MyTable : LongIdTable() {
// ...
val created = timestamp("created").defaultExpression(CurrentTimestamp).databaseGenerated()
val modified = timestamp("modified").defaultExpression(CurrentTimestamp).databaseGenerated()
// ...
}
```

and the following entity:
```kotlin
class MyEntity(id: EntityID) : LongEntity(id) {
companion object : LongEntityClass(MyTable)

// ...
val created by MyTable.created
var modified by MyTable.modified
// ...
}
```

Now, if I create the entity with:
```kotlin
val obj = MyEntity.new {
// All properties are initialized except created and modified
}

// Fails
assertNotNull(obj.created)
```

But in the IDEA debugger, if I click on the property, it shows the Instant object that has been created in the database.
If I run into the assertion after clicking the property, the assertion doesn't fail anymore.
How is that possible?

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.