Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: Allow non-primary-key generated fields, e.g. timestamps, counters, etc. #96

Merged

Conversation

vnayar
Copy link
Contributor

@vnayar vnayar commented Dec 15, 2024

Currently, HibernateD treats @Generated as being inseparable from @Id, it is assumed that any generated field is also the primary key.

However, a database table can have non-primary-key columns that are @Generated. For example, a database that keeps track of a timestamp, which is populated via a DB trigger or a default value, e.g. now(), may exist alongside a separate primary key.

In order to support this kind of data, the assumption that @Generated implies @Id needs to be undone. This PR changes the core logic and also adds a basic test around generated columns to validate schema generation as well as the ability to insert and update such records.

Currently, HibernateD treats `@Generated` as being inseparable from `@Id`,
it is assumed that any generated field is also the primary key.

However, a database table can have non-primary-key columns that are `@Generated`.
For example, a database that keeps track of a timestamp, which is populated
via a DB trigger or a default value, e.g. `now()`, may exist alongside a
separate primary key.

In order to support this kind of data, the assumption that `@Generated` implies
`@Id` needs to be undone. This PR changes the core logic and also adds a basic
test around generated columns to validate schema generation as well as the ability
to insert and update such records.
@vnayar vnayar force-pushed the bug/multiple-generated-properties-per-entity branch from 0dca3a0 to 141df5f Compare December 15, 2024 22:34
@vnayar
Copy link
Contributor Author

vnayar commented Dec 18, 2024

I've been testing this in a production system, and so far so good. The most common use-case is being able to read and make use of generated columns, such as the timestamp when a record was inserted or updated, that isn't the primary key.

@SingingBush SingingBush merged commit c219b4d into buggins:master Dec 22, 2024
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants