Я пытаюсь получить объект User, который, помимо имени пользователя и пароля, имеет логическую переменную, которая указывает, был ли он удален или нет. Логическое var называется delete. В моей базе данных все пользовательские объекты являются ложными.
Я попробовал ClassicalSyntax, но он выдал другую ошибку.
public User loginUser(String username, String password) {
TypedQuery<User> query = em.createQuery("Select u from User u " + "where u.username LIKE "
+ "?1 AND u.password LIKE " + "?2 AND u.delete =:delete", User.class);
query.setParameter(1, username);
query.setParameter(2, password);
query.setParameter("delete", false);
User foundUser = query.getSingleResult();
return foundUser;
}
Он работает с двумя другими определениями u.username и u.password, но когда я добавляю u.delete, возникает ошибка. Я ожидаю, что это вернет объект.
SEVERE: Servlet.service() for servlet [Jersey Web Application] in context with path [/webproject] threw exception [java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: u near line 1, column 101 [Select u from com.ikubinfo.project.model.User u where u.username LIKE ?1 AND u.password LIKE ?2 AND u.delete =:delete]] with root cause
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: u near line 1, column 101 [Select u from com.ikubinfo.project.model.User u where u.username LIKE ?1 AND u.password LIKE ?2 AND u.delete =:delete]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:304)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:342)
at com.ikubinfo.project.repository.UserRepository.loginUser(UserRepository.java:34)
at com.ikubinfo.project.controller.UserResource.deleteUser(UserResource.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:469)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:391)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:80)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:253)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)