Skip to content

Possibility to have a non-primary field with sequence generator or default value [DATAJDBC-623] #842

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

Closed
spring-projects-issues opened this issue Oct 28, 2020 · 1 comment
Assignees
Labels
type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Johan Blomgren opened DATAJDBC-623 and commented

I'm not sure if it's correct for me to post my improvement requests here? 

But i would like to one of these, or both.

Example with kotlin/postgres

Define sequence generator

@Table("foo")
data class Foo(
    @Id 
    val id: UUID, 
    @Sequence("external_id_seq") 
    val externalId: Long)
INSERT INTO foo(id, external_id) VALUES (?, nextval('external_id_seq')

or
Field uses default value if null 

@Table("foo")
data class Foo(
  @Id 
  val id: UUID, 
  @EmptyOnNull 
  val externalId: Long)
--Creates query, ignoring externalId since it should be empty if null. 
INSERT INTO foo(id) values (?)

No further details from DATAJDBC-623

@spring-projects-issues
Copy link
Author

Jens Schauder commented

Yes, this is the correct place for improvement requests.

We won't implement these though.
The problem is that we don't have an efficient, reliable way to get the values back from the database, since not all return all generated values.

You can implement the sequence variant using an EntityCallback, that gets the new value from the sequence and sets it in the entity.
This adds a little overhead for an additional db roundtrip which can be limited by implementing a Hi/Lo algorithm as Hibernate offers.

We might eventually provide such listeners for easy use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants