Reputation: 111
Here's my stack:
- Micronaut 1.3.2
- Java 8
- Eclipse STS 4
Pom.xml excerpt:
<dependency>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-jdbc-hikari</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-hibernate-jpa</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-hibernate-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>1.0.0.M1</version>
</path>
My Repository:
import io.micronaut.data.annotation.Repository;
import io.micronaut.data.repository.CrudRepository;
@Repository
public interface UsuarioRepository extends CrudRepository<UsuarioModel, Long> { }
My Service:
private UsuarioDTO atualizar(UsuarioDTO usuario) {
UsuarioModel modelo = new UsuarioModel();
modelo.setIdade(usuario.idade);
modelo.setNick(usuario.nick);
modelo.setNome(usuario.nome);
modelo.setPassword(usuario.password);
this.usuarioRepository.update(modelo);
return usuario;
}
application.yml:
micronaut:
application:
name: micronaut-chatroom
server:
cors:
enabled: true
datasources:
default:
url: jdbc:h2:mem:devDb
driverClassName: org.h2.Driver
username: sa
password: ''
schema-generate: CREATE_DROP
dialect: H2
jpa:
default:
entity-scan:
packages: 'com.cr.model'
When I'm running Install maven command on my Micronaut project I get the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project micronaut-chatroom: Compilation failure [ERROR] Unable to implement Repository method: UsuarioRepository.update(Object entity). No possible implementations found.
Has someone been through it?
Thanks in advance!
EDIT
Here's my UsuarioModel class
@Entity(name = "Usuario")
@Table(name = "usuario")
public class UsuarioModel implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7468837154917949190L;
@Id
@GeneratedValue
private Long id;
private String nome;
private String nick;
private String idade;
private String password;
@OneToMany
private List<MensagemModel> mensagens;
//Getter/Setters ommited
}
And also my MensagemModel class:
@Entity(name = "Mensagem")
@Table(name = "mensagem")
public class MensagemModel implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7634793331670289187L;
@Id
@GeneratedValue
private Long id;
@CreationTimestamp
private LocalDateTime data;
private String conteudo;
@ManyToOne
@JoinColumn(name = "usuario_id")
private UsuarioModel usuario;
//Getter/Setter ommited
}
Upvotes: 5
Views: 7763
Reputation: 11
I faced the same problem. The fix to the problem was to create getters and setters for the fields in the model.
Upvotes: 1
Reputation: 360
There are 2 possible sources for the @Id
decorator in micronaut:
io.micronaut.data.annotation
jakarta.persistence-api
dependency in mavenAs you are decorating the class with @Entity
I suppose you are using the latter set of decorators. or at least a mix of the 2 sources.
As basic debug step you could try removing any reference to javax.persistance and use native only decorators. So, as instance, do not use @Entity
but rather @MappedEntity
and so on.
simply comment out any import from javax.persistence.*
and try with native io.micronaut.data.annotation*
.
this would make clearer - I hope- if the issue lies in some twist of the annotation process.
Upvotes: 3