dieselpoint / norm

Access a database in one line of code.
Other
205 stars 36 forks source link

Postgresql and default #61

Open ZZerog opened 3 years ago

ZZerog commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

ZZerog commented 3 years ago

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 commented 3 years ago

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.