我有一个工作查询,我需要通过使用常量枚举值进行过滤来修改.
现在它看起来像这样:
public static final String venueQuery =
"select distinct v from package.Venue v "
+ "<some joins here> "
+ "WHERE v.venueType = package.enums.VenueType.VOUCHER_PROVIDER ";
Run Code Online (Sandbox Code Playgroud)
以这种方式更改数据会导致
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token
Run Code Online (Sandbox Code Playgroud)
列定义如下:
@Enumerated(EnumType.STRING)
@Column(name = "venue_type")
private VenueType venueType;
Run Code Online (Sandbox Code Playgroud)
枚举定义看起来像这样:
public enum VenueType {
RESTAURANT, BAR, CAFE, FUN_CLUB, VOUCHER_PROVIDER
}
Run Code Online (Sandbox Code Playgroud)
我确信查询的其他部分工作正常,因为删除它后,不会抛出任何异常.
是否有在HQL查询中设置常量枚举值的技巧?
我从maven收到此错误消息:
[ERROR] Failed to execute goal on project battleships: Could not resolve dependencies for project com.miteff.travelex:battleships:wa
r:2.0.0-BUILD-SNAPSHOT: The following artifacts could not be resolved: javax.jms:jms:jar:1.1, com.sun.jdmk:jmxtools:jar:1.2.1, com.s
un.jmx:jmxri:jar:1.2.1: Could not transfer artifact javax.jms:jms:jar:1.1 from/to java.net (https://maven-repository.dev.java.net/no
nav/repository): Cannot access https://maven-repository.dev.java.net/nonav/repository with type legacy using the available connector
factories: BasicRepositoryConnectorFactory: Cannot access https://maven-repository.dev.java.net/nonav/repository with type legacy u
sing the available layout factories: Maven2RepositoryLayoutFactory: Unsupported repository layout legacy -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, …
Run Code Online (Sandbox Code Playgroud) 我有名字,工资和员工部门的数据库.我需要一个查询来获得每个部门薪水最高的员工.
数据库:
create table test(
employee_name VARCHAR(255),
department VARCHAR(255),
salary INT
);
Run Code Online (Sandbox Code Playgroud)
数据:
INSERT INTO test(employee_name, department, salary) VALUES
("John", "DepartmentA", 1500),
("Sarah","DepartmentA", 1600),
("Romel","DepartmentA", 1400),
("Victoria","DepartmentB", 1400),
("Maria", "DepartmentB", 1600);
Run Code Online (Sandbox Code Playgroud)
我的尝试:
1.1 WHERE MAX(薪水)=工资GROUP BY部门
SELECT employee_name, salary FROM test WHERE MAX(salary) = salary GROUP BY department;
ERROR 1111 (HY000): Invalid use of group function
Run Code Online (Sandbox Code Playgroud)
1.2.当我用硬编码值替换MAX(薪水)时,它按预期工作:
SELECT employee_name, salary FROM test WHERE 1600 = salary GROUP BY department;
+---------------+--------+
| employee_name | salary |
+---------------+--------+
| Sarah | 1600 …
Run Code Online (Sandbox Code Playgroud)