-2
I’m creating a little project using spring boot,:
org.springframework.data.relational.core.conversion.DbActionExecutionException: Failed to execute DbAction.InsertRoot(entity=br.com.voyager.central.model.Movie@640c216b, generatedId=null)
Well this is the result of the execution of :
@Test
public void insert() {
Movie filme = new Movie("Cachorros de novo").setDescription("A historia de um vira-lata");
repository.save(filme);// <- Erro
}
To add the most comprehensive information here to my Movie class and my super Mappedsuperclass:
- Mappedsuperclass
@MappedSuperclass
public abstract class Entity implements Serializable{
/**
*
*/
private static final long serialVersionUID = -4231451612698516409L;
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", unique = true)
protected UUID uuid;
public Entity setUUID(@NonNull UUID uuid) {
this.uuid = uuid;
return this;
}
public UUID getUUID() {
return this.uuid;
}
@Override
public boolean equals(Object object) {
// primeiro verifica se o outro object não é nulo
if (object != null)
if(object instanceof Entity)// Verificar se e uma intancia de um movie
if (this.uuid.equals(((Entity)object).getUUID())) {// verificar se é o mesmo uuid
return true;
}
return false;
}
}
- Movie class
@Entity
public class Movie extends br.com.voyager.central.model.Entity{
/**
* Serial da versãod a classe
*/
private static final long serialVersionUID = -7743281799376449433L;
private String name;
private String description;
private String midia;
public Movie() {}
public Movie(@NonNull String name) {
this.name = name;
}
public Movie(@NonNull UUID uuid) {
this.uuid = uuid;
}
public Movie(@NonNull UUID uuid ,@NonNull String name) {
this.uuid = uuid;
this.name = name;
}
public Movie(@NonNull String uuid ,@NonNull String name) {
this.uuid = UniqueIdentifier.getUUIDByString(uuid);
this.name = name;
}
public String getDescription() {
return description;
}
public Movie setDescription(@NonNull String desc) {
this.description = desc;
return this;
}
public String getMidia() {
return midia;
}
public Movie setMidia(@NonNull String midia) {
this.midia = midia;
return this;
}
public Movie setName(@NonNull String name) {
this.name = name;
return this;
}
public String getName() {
return this.name;
}
@Override
public Movie setUUID(@NonNull UUID uuid) {
super.setUUID(uuid);
return this;
}
}
Note that I am using UUID as the handle and the versions I am using:
- mysql-Connector-java v5.1.48
- spring-boot-Starter-data-jpa v2.1.9.RELEASE
And my pom is so riders:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.voyager</groupId>
<artifactId>central</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>central</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.version>2.1.9.RELEASE</spring.version>
<hibernate.version>5.2.6.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>${spring.version}</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>5.1.48</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Please help me searched everywhere for letting this automatic generation will get very annoying if I have to generate and assign one before insertion. Thanks for your help
The id really needs to be a UUID?
– nullptr
I sincerely do not ,but I prefer it to be so friend
– Gil
Post the full stacktrace for kindness
– nullptr
You refer to the point where the error occurs?
– Gil