Hi,
I wonder if and how it is possible to search for entites by defining associated attributes. I want to use Criteria queries.
Better to show an example. I have an entity like this with a many-to-many association "businesses":
Code:
@Entity
public class Asset extends Basic {
// Fields
@Id
private Long id;
@ManyToOne
private Users validatedByUser;
@ManyToMany(targetEntity = Business.class)
@JoinTable(name = "ASSET_BUSINESSES", joinColumns = { @JoinColumn(name = "ASSETID") }, inverseJoinColumns = { @JoinColumn(name = "BUSINESSID") })
private List<Business> businesses;
// geters setters
There is a join table "asset_businesses". I tried to use Criteria like this:
Code:
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Asset.class);
criteria.add(Restrictions.eq("businesses", listOfBusinesses));
criteria.list();
Code:
Unfortunately I get an Exception: java.sql.SQLException: Missing IN or OUT parameter at index:: 1
I want to get all Asset entities that are associated with the businesses I provided.
What other way is there to achieve this?