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

Postgresql and default #61

Open
ZZerog opened this issue Jun 22, 2021 · 4 comments
Open

Postgresql and default #61

ZZerog opened this issue Jun 22, 2021 · 4 comments

Comments

@ZZerog
Copy link

ZZerog commented Jun 22, 2021

Hi. I still cannot catch this situation.

table column:
verification_hash uuid DEFAULT uuid_generate_v1() UNIQUE

POJO:

    @Column(name = "verification_hash")
    public String verificationHash;

When the insert method is called, column verification_hash is null.
I will try to implement my own JPA serialization for that or am I doing something wrong? Missing some annotation or something?

Thx

@ZZerog
Copy link
Author

ZZerog commented Jun 22, 2021

OK. This is a working java solution.
But a better solution (I think) is to generate UUID on the SQL side.

    @Column(name = "verification_hash")
    public UUID verificationHash = UUID.randomUUID();

@ccleve
Copy link
Member

ccleve commented Jun 22, 2021

I actually use the Java solution in my apps because it solves a problem with batch inserts. The postgres jdbc driver does not return generated ids in the correct order when you do a batch insert.

For single inserts add the @id and @GeneratedValue annotations to your primary key. See the docs.

Reopen this issue if that doesn't solve the problem.

@ccleve ccleve closed this as completed Jun 22, 2021
@ZZerog
Copy link
Author

ZZerog commented Jun 22, 2021

When the column is a primary key,  annotations work as expected, but what to do when the column is NOT the primary key? @GeneratedValue works only with Long value and means something as 'auto increment', right ?

So the java solution is only working solutions

@ccleve
Copy link
Member

ccleve commented Jun 22, 2021

Are you using the most recent version of Norm? 1.0.4. There were a few changes to the way generated values are returned.

Try it with just @GeneratedValue. If that doesn't work, I'll have a look at it.

@ccleve ccleve reopened this Jun 22, 2021
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

No branches or pull requests

2 participants