Hi,
I have two entity classes phone and link. The phone has a one to many relation with link on pin.Since I want a query that returns the count as well as some fields I have another POJO called details grid in the package mars.util which has similar fields as the items the query fetches.
I am also using JPA as a wrapper. Here is the query I have:
Code:
Query q = manager.createQuery("Select new mars.util.DetailsGrid(lp.psn_pin,lp.seq_num,lp.phone," +
" count(distinct src.srcname),min(src.date_reported),max(src.date_reported),count(src.date_reported))" +
"From Phone lp Join lp.phonevaluelink src"+
"Where lp.psn_pin = :pin"+
"Group By lp.phone" +
"Order by max(src.date_reported) desc");
q.setParameter("pin",pin);
List<DetailsGrid> griddetails= q.getResultList();
My entities Phone looks something like this:
Code:
public class Phone implements Serializable{
private long psn_pin;
...
private Set<PhoneValueLink> phonevaluelink;
@Id
@Column(name="PSN_PIN")
public long getPsn_pin() {
return psn_pin;
}
public void setPsn_pin(long psnPin) {
psn_pin = psnPin;
}
...
....
@OneToMany(mappedBy ="phone")
public Set<PhoneValueLink> getPhonevaluelink() {
return phonevaluelink;
}
public void setPhonevaluelink(Set<PhoneValueLink> phonevaluelink) {
this.phonevaluelink = phonevaluelink;
}
And My Phonevaluelink is something like this
Code:
public class PhoneValueLink implements Serializable {
...
..
private Phone phone;
..
@ManyToOne
@JoinColumn(name="PSN_PIN", referencedColumnName="PSN_PIN", insertable=false, updatable=false)
public Phone getphone() {
return lphone;
}
public void setphone(Phone phone) {
this.phone = phone;
}
The error I am getting now is:
unexpected token: lp
12:44:26,269 ERROR [] java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: lp near line 1,Any idea what I am doing wrong?