@Id
@Column(name="Item", unique = true, nullable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int itemId;
@Column(name="ItemName")
private String itemName;
@Column(name="ItemPrice")
private double itemPrice;
@Column(name="status")
private String status;
@Column(name="image")
private String image;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "RestaurantId", nullable = false)
private Restaurant restaurant;
this is my Entity class ,
public List<FoodItem> getFoodItems(Restaurant restaurant) {
Session session=getSession();
List<FoodItem> list=null;
NativeQuery<?> query = session.createNativeQuery("SELECT " +
" \"Item\"," +
" \"ItemName\"," +
" \"ItemPrice\"," +
" \"RestaurantId\"," +
" \"status\"," +
" \"image\" " +
"FROM \"SYSTEM\".\"FoodItem\" where \"RestaurantId\"="+restaurant.getRestaurantId());
list = (List<FoodItem>) query.getResultList();
return list;
}
when i run this method, it doesn't return me a List<FoodItem> instead it returns a List<Array> like this,
[
[
1,
"Pasta",
55,
14,
"Veg",
null
],
[
2,
"Burger",
35,
14,
"Veg",
null
]
]
and if i try to set the restaurant object to null in each object in the list,
for(int index=0 ;index< list.size();index++)
list.get(index).setRestaurant(null);
i got ClassCastException. i need the response in key : value pair as per my entity class can anyone solve this for me. thanks. [update] Solved!