-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate JPA query
PostPosted: Tue Sep 27, 2011 4:18 am 
Newbie

Joined: Tue Sep 27, 2011 4:11 am
Posts: 14
Hello all,
Can anyone please help me with this query. The scenario is i need to get data from two different tables and show them in jtable. For this i have used secondary table annotation to create a single class for the purpose. Now i need to create a query for this but i am having trouble with it. The query is :

select pi.productcode , pi.productname , pi.barcodeno , in.saleunitprice , in.quantity from inventory as in inner join in.ProductInformation as pi WHERE pi.productid = in.productid


Quote:
Where productinformation and inventory are two tables from which i want to get data from and product Id is the primary key in both of them


But it keeps giving me this error:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: in near line 1, column 58 [ select pi.productcode , pi.productname , pi.barcodeno , in.saleunitprice , in.quantity from inventory as in inner join in.ProductInformation as pi WHERE pi.productid = in.productid ]


the class is :



@Entity
@Table(name="productinformation")
@SecondaryTable(name="inventory")

public class InventoryCombined {



String allocatedlocation;
Integer allocationid;
Integer productid;
String sellable_notsellable;
Date sellablefromdate;
Date sellabletill;
Integer shelflocation;
Integer quantity;
Integer receivedquantity;
Integer soldquantity;
Integer inhandquantity;
Integer costtotalprice;
Integer saleunitprice;
Integer notsellablereasoncode;
Integer inventorybarcode;

Integer productcode;
String productname;
Integer barcodeno;
String productcomptype;




@Column(table="inventory")
public Integer getAllocationid() {
return allocationid;
}
public void setAllocationid(Integer allocationid) {
this.allocationid = allocationid;
}


@Column(table="inventory")
public String getAllocatedlocation() {
return allocatedlocation;
}
public void setAllocatedlocation(String allocatedlocation) {
this.allocatedlocation = allocatedlocation;
}


@Id
@GeneratedValue
public Integer getProductid() {
return productid;
}
public void setProductid(Integer productid) {
this.productid = productid;
}



@Column(table="inventory")
public String getSellable_notsellable() {
return sellable_notsellable;
}
public void setSellable_notsellable(String sellable_notsellable) {
this.sellable_notsellable = sellable_notsellable;
}


@Column(table="inventory")
public Date getSellablefromdate() {
return sellablefromdate;
}
public void setSellablefromdate(Date sellablefromdate) {
this.sellablefromdate = sellablefromdate;
}


@Column(table="inventory")
public Date getSellabletill() {
return sellabletill;
}
public void setSellabletill(Date sellabletill) {
this.sellabletill = sellabletill;
}


@Column(table="inventory")
public Integer getShelflocation() {
return shelflocation;
}
public void setShelflocation(Integer shelflocation) {
this.shelflocation = shelflocation;
}


@Column(table="inventory")
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}


@Column(table="inventory")
public Integer getReceivedquantity() {
return receivedquantity;
}
public void setReceivedquantity(Integer receivedquantity) {
this.receivedquantity = receivedquantity;
}


@Column(table="inventory")
public Integer getSoldquantity() {
return soldquantity;
}
public void setSoldquantity(Integer soldquantity) {
this.soldquantity = soldquantity;
}



@Column(table="inventory")
public Integer getInhandquantity() {
return inhandquantity;
}
public void setInhandquantity(Integer inhandquantity) {
this.inhandquantity = inhandquantity;
}



@Column(table="inventory")
public Integer getCosttotalprice() {
return costtotalprice;
}
public void setCosttotalprice(Integer costtotalprice) {
this.costtotalprice = costtotalprice;
}


@Column(table="inventory")
public Integer getSaleunitprice() {
return saleunitprice;
}
public void setSaleunitprice(Integer saleunitprice) {
this.saleunitprice = saleunitprice;
}



@Column(table="inventory")
public Integer getNotsellablereasoncode() {
return notsellablereasoncode;
}
public void setNotsellablereasoncode(Integer notsellablereasoncode) {
this.notsellablereasoncode = notsellablereasoncode;
}


@Column(table="inventory")
public Integer getInventorybarcode() {
return inventorybarcode;
}
public void setInventorybarcode(Integer inventorybarcode) {
this.inventorybarcode = inventorybarcode;
}





I am sorry for the long post but it was necessary to put the class here.


SO please can anyone help me this. I would be very thankful to him.


Haris Tasawar.


Top
 Profile  
 
 Post subject: Re: Hibernate JPA query
PostPosted: Tue Sep 27, 2011 4:33 am 
Newbie

Joined: Tue Sep 27, 2011 4:11 am
Posts: 14
hey i found the error... It seems its not getting the object token "in" of the inventory table and "pi" of the product information.

Can you guys please tell me how to solve this problem????


Top
 Profile  
 
 Post subject: Re: Hibernate JPA query
PostPosted: Tue Sep 27, 2011 5:25 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
"in" is a keyword in HQL. You might try using a different alias.

Do you really need the pi.productid = in.productid filter? Hibernate should add that automatically from the inner join.


Top
 Profile  
 
 Post subject: Re: Hibernate JPA query
PostPosted: Tue Sep 27, 2011 7:20 am 
Newbie

Joined: Tue Sep 27, 2011 4:11 am
Posts: 14
thanks nordborg.... i will try this........ another thing, have i defined the class correctly..... Could there be something wrong with it?


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.