Я пытаюсь создать Именованный запрос с условием внутреннего соединения в классе Entity. Однако приложение не запускается с исключением.
Объект:
@Entity
@Table(name = "fooentry")
@NamedQuery(name="query1", query="SELECT foo.id, foo.name, foo.type, foo.action, foo.createdDateTime FROM FooEntity foo " +
"INNER JOIN (SELECT name, type, MAX(createdDateTime) AS recenttime FROM FooEntity GROUP BY name, type) recententry " +
"ON (foo.name = recententry.name AND foo.type = recententry.type) AND createdDateTime = recenttime AND isExported = false",
lockMode=PESSIMISTIC_WRITE)
public class FooEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "name")
@NotNull
private String msisdn;
@Column(name = "type")
@NotNull
private String iccid;
@Column(name = "action")
@NotNull
private Long inventoryActionId;
@NotNull
@Column(name = "is_exported")
private Boolean isExported;
@Column(name = "created_date_time")
@NotNull
private LocalDateTime createdDateTime;
//setter and getter
}
Исключение: приложение не запускается со следующим исключением.
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.HibernateException: Errors in named queries:
query1 failed because of: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 161