I do have a problem query problem with spring and hibernate.
I’ve got a class called Car which maps ManyToMany to my class Inventory. Inventory btw holds no references to the Car class.
This causes spring and hibernate to create the mapping table car_loading with a fk to the car and a fk to the inventory table.
I now want to query the inventory for a special car:
String squery = "SELECT i from Inventory i, car_loading loads WHERE i.id = loads.loading AND car = ?";
But I am getting the exception
org.hibernate.hql.ast.QuerySyntaxException: car_loading is not mapped
FYI: Hibernate doesn’t support the JOIN ON x.a = y.b leading me to do it that way…
Thanks inn advance for any help!
EDIT – My Mapping
public class Car {
@OneToOne
private Driver driver;
@ManyToMany(cascade=CascadeType.ALL)
private List<Inventory> loading = new ArrayList<Inventory>();
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern="dd:MM:yyy HH:mm")
private Date lastModified;
//...
}
public class Inventory {
private Integer shouldAmount;
private Integer minAmount;
private Integer isAmount;
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern="dd:MM:yyy HH:mm")
private Date lastModified;
//..
}
I saw this question and wanted to updated it. I did it the wrong way around. I could simply query the car and return all inventorys within this car. Because there is a relation from car to inventory, but not the other way around. So query a specific car and simply return the inventory list attribute did it for me…