每当执行此查询时,我都会遇到JPA问题
@NamedQuery(name = "Usuario.getUsuarioIntento", query = "SELECT u.intentos_id FROM Usuario u WHERE u.username = :username and u.borrado = 0")
我收到此错误:
java.lang.IllegalArgumentException: NamedQuery of name: Usuario.getUsuarioIntento not found.
但如果我执行此查询
@NamedQuery(name = "Usuario.getUsuarioIntento", query = "SELECT u.id FROM Usuario u WHERE u.username = :username and u.borrado = 0")
工作正常,为什么?
我的桌子,Usuario:
我尝试使用其他专栏作为'superusuario','version_jpa'并且不起作用,唯一正常工作的列是'id,'borrado'和'username'
Class Usuario:
@Temporal(TemporalType.TIMESTAMP)
private Date fechaCreacion;
@Id
@GeneratedValue (strategy=GenerationType.AUTO)
private int id;
@OneToOne(cascade = CascadeType.ALL)
private Password password;
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.LAZY)
private List<Password> clavesAntiguas;
@OneToOne
private Persona persona;
private String sessionId;
private String username;
@ManyToOne(cascade = CascadeType.REFRESH)
private Rol rol;
@ManyToOne(cascade = CascadeType.REFRESH)
private Perfil perfil;
@OneToOne (cascade = CascadeType.ALL)
private IntentosBloqueo intentos;
private boolean superUsuario;
private int borrado;
private int esManager;
@OneToMany ( cascade = {CascadeType.ALL} , fetch = FetchType.LAZY)
private Collection<UsuarioSociedad> sociedades;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
@JoinTable (name="USR_UND_VIS",
joinColumns={
@JoinColumn (name="ID_USU", table="USUARIO", referencedColumnName="ID"),
},
inverseJoinColumns=
@JoinColumn (name="ID_UNI", table="UND_ORG", referencedColumnName="ID")
)
private List<UnidadOrganizativa> unidadesVisibles;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
@JoinTable (name="USR_UND_DIS",
joinColumns={
@JoinColumn (name="ID_USU", table="USUARIO", referencedColumnName="ID"),
},
inverseJoinColumns=
@JoinColumn (name="ID_UNI", table="UND_ORG", referencedColumnName="ID")
)
private List<UnidadOrganizativa> unidadesDisponibles;
答案 0 :(得分:0)
因为命名查询适用于Entity objetc而不是数据库列。您尝试查找包含该id的另一个实体对象。在这种情况下,您的命名查询将为您提供该实体类的对象,并且从该对象,您可以获得该实体的id或whtever fiels。
JPA命名查询与SQL或oracle查询不同。
在数据库中我的列名是xyz,但在实体中你的列名是ABC,那么你必须在命名查询而不是XYZ中获取ABC。