I am having a problem with the following code
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController' defined in file [C:\Users\USERNAME\IdeaProjects...\application\ui\security\controller\LoginController.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginServiceImpl' defined in file [C:\Users\USERNAME\IdeaProjects\...\core\domain\login\LoginServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginRepository' defined in be.mypackage.core.persistence.LoginRepository defined in @EnableJpaRepositories declared on DomainConfig: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List be.mypackage.core.persistence.LoginRepository.findListIdentifiant()!
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginServiceImpl' defined in file [C:\Users\USERNAME\IdeaProjects\....\core\domain\login\LoginServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginRepository' defined in be.mypackage.core.persistence.LoginRepository defined in @EnableJpaRepositories declared on DomainConfig: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List be.mypackage.core.persistence.LoginRepository.findListIdentifiant()!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginRepository' defined in be.mypackage.core.persistence.LoginRepository defined in @EnableJpaRepositories declared on DomainConfig: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List be.mypackage.core.persistence.LoginRepository.findListIdentifiant()!
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List be.mypackage.core.persistence.LoginRepository.findListIdentifiant()!
Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode
\-[IDENT] IdentNode: 'loginRole' {originalText=loginRole}
Caused by: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode
\-[IDENT] IdentNode: 'loginRole' {originalText=loginRole}
I'm trying to retrieve some value from the table but not all of it. And I have this error. I don't want to use @Transient because it prevents me from retrieving the password value at another time.
the problem seems to be with the enum field, if I remove it from the query, with an appropriate constructor, the query no longer returns an error when launching the program.
There must be something simple that I'm not doing right.
my request jpa
import be.mypackage.core.domain.login.Login;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface LoginRepository extends JpaRepository<Login, Integer> {
@Query(value = "SELECT idLogin, identifiant, societe, loginRole FROM Login")
List<Login> findListIdentifiant();
}
My Class entity Login
package be.mypackage.core.domain.login;
import be.mypackage.core.domain.societe.Societe;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Transient;
@Entity
@SQLDelete(sql = "UPDATE login SET status_actif = false WHERE id_login=?")
@Where(clause = "status_actif <> 'false'")
public class Login {
@Id
@Column(nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer idLogin;
@Column(length = 100, unique = true)
private String identifiant;
//@Transient
@Column(length = 100)
private String motDePasse;
@ManyToOne(fetch = FetchType.LAZY) // OK
@JoinColumn(name = "no_societe", nullable = false)
private Societe societe;
@Transient
@Column(name = "status_actif", nullable = false)
private Boolean statusActif;
@PrePersist
public void fixStatusActif() {
this.statusActif = true;
}
@Enumerated(EnumType.STRING)
@Column(name = "role", unique = true, length = 30)
private LoginRole loginRole;
public Login() {
}
// jpa request work with this constructor
public Login(Integer idLogin, String identifiant, Societe societe) {
this.idLogin = idLogin;
this.identifiant = identifiant;
this.societe = societe;
}
// not work
public Login(Integer idLogin, String identifiant, Societe societe, LoginRole loginRole) {
this.idLogin = idLogin;
this.identifiant = identifiant;
this.societe = societe;
this.loginRole = loginRole;
}
public Integer getIdLogin() {
return idLogin;
}
public void setIdLogin(Integer idLogin) {
this.idLogin = idLogin;
}
public String getIdentifiant() {
return identifiant;
}
public void setIdentifiant(String identifiant) {
this.identifiant = identifiant;
}
public String getMotDePasse() {
return motDePasse;
}
public void setMotDePasse(String motDePasse) {
this.motDePasse = motDePasse;
}
public Boolean getStatusActif() {
return statusActif;
}
public void setStatusActif(Boolean statusActif) {
this.statusActif = statusActif;
}
public Societe getSociete() {
return societe;
}
public void setSociete(Societe societe) {
this.societe = societe;
}
public LoginRole getLoginRole() {
return loginRole;
}
public void setLoginRole(LoginRole loginRole) {
this.loginRole = loginRole;
}
@Override
public String toString() {
return identifiant;
}
}
Class Enum
package be.mypackage.core.domain.login;
public enum LoginRole {
ROLE_ADMIN,
ROLE_MANAGER,
ROLE_EMPLOYEE,
ROLE_EMPLOYEE_READ;
}
findAll query works fine with enum but I can't exclude password from query
as you can see the role (enum) field is well getter with findAll but does not meet my security requirements