Springboot GenerationType.UUID not working

@Table(name = "Product")
public class Product {

@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
@Table(name = "Product")
public class Product {

@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
On create drop the sql field becomes:
id uuid not null primary key,
id uuid not null primary key,
upon inserting a row without specifying my Id field i get the error:
[23502] ERROR: null value in column "id" of relation "product" violates not-null constraint
[23502] ERROR: null value in column "id" of relation "product" violates not-null constraint
5 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @Ed! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Peter Rader
Peter Rader10mo ago
Hey Edd, you need to call myProduct.setId(UUID.randomUUID()); before saving to the database.
tjoener
tjoener10mo ago
That is bad advice. JPA or spring should do this for you Set strategy to Auto, that should work or, extend AbstractPersistable<UUID>, and remove all id related stuff from your own entity
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?