0

I am using HIBERNATE version: 5.6.15.Final, to try to generate a UUID when creating a relational table, I have the following definition of class attributes:

@Entity
@Table(name = "Regiones")
public class Region implements Serializable {
    private static final long SerialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(
      name = "UUID", 
      strategy = "org.hibernate.id.UUIDGenerator"
    )
    @Getter
    @Setter
    private UUID Id;
}

But I get a runtime error: java.sql.SQLException: Field 'id' doesn't have a default value and the program stops. Is the strategy path defined in the GenericGenerator different for this version of hibernate? Or am I wrong about something else?

Gradle dependencies:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    // https://mvnrepository.com/artifact/mysql/mysql-connector-java
    implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.33'

    // https://mvnrepository.com/artifact/org.hibernate/hibernate-validator
    implementation group: 'org.hibernate', name: 'hibernate-validator', version: '7.0.5.Final'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Toms_Hd3z
  • 129
  • 1
  • 11
  • May be possibly a duplicate of https://stackoverflow.com/questions/804514/hibernate-field-id-doesnt-have-a-default-value – Ale Zalazar Jun 08 '23 at 17:21

0 Answers0