Hi Everyone:
I am using Spring Framwork with Hibernate/JPA to write a HQL query. My problem is with my enum FeedType (Using the first constructor from FEED -> first parameter is a FeedType), I get an error that says: unexpected end of subtree and it points to the query shown below. When I choose the second constructor from the domain, everything works perfectly. Any suggestion is appreciated. My query is below:
@Query("SELECT new YesIHaveMyPackageNameHere.Feed(YesIHaveMyPackageNameHere.FeedType.SLEEP, se.startDate,'sleeptracker', cast(sum(se.minutesAsleep) as big_decimal), '','asleep',p) FROM Person p JOIN p.sleepProfile sp JOIN sp.sleepEpisodes se WHERE p.id = :userId order by se.startDate desc group by se.startDate") public List<Feed> getFeedFromSleep(@Param("userId") Long userId, Pageable page);
//My Domain:
@Entity @Table(name="Feed") @Audited public class Feed {
public Feed(FeedType type, Date date, String link, BigDecimal value, String app, String unitType, Person person) { super(); this.type = type; this.date = date; this.link = link; this.value = value; this.app = app; this.unitType = unitType; this.person = person; }
public Feed(Date date, String link, BigDecimal value, String app, String unitType, Person person) { super(); this.date = date; this.link = link; this.value = value; this.app = app; this.unitType = unitType; this.person = person; }
public Feed() { } @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="Id") private Long id; @Column(name="type") @Enumerated(EnumType.STRING) private FeedType type; @Column(name="date") private Date date; @Column(name="link") private String link; @Column(name="value") private BigDecimal value; @Column(name="app") private String app; @Column(name="unitType") private String unitType; @ManyToOne private Person person; public BigDecimal getValue() { return value; }
public void setValue(BigDecimal value) { this.value = value; } public String getUnitType() { return unitType; }
public void setUnitType(String unitType) { this.unitType = unitType; }
public String getApp() { return app; }
public void setApp(String app) { this.app = app; } public FeedType getType() { return type; }
public void setType(FeedType type) { this.type = type; }
public Date getDate() { return date; }
public void setDate(Date date) { this.date = date; }
public String getLink() { return link; }
public void setLink(String link) { this.link = link; }
public Person getPerson() { return person; }
public void setPerson(Person person) { this.person = person; } }
//Enum
public enum FeedType {
SLEEP("sleep"), FITNESS("fitness"), NUTRITION("nutrition");
private FeedType(String name) { this.name = name; }
private final String name;
public String toString() { return name; }
public String getName(){ return this.name; }
}
|