-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate problem with HQL and enum in constructor query
PostPosted: Sat Apr 06, 2013 3:15 pm 
Newbie

Joined: Sat Apr 06, 2013 3:08 pm
Posts: 1
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;
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.