wolli wrote:
Put hibernate.show_sql=true in your configuration and make sure that logging is enabled.
Can you post your mappings ?
I am using JBoss with log4j. I had to search for the xml configuration.
The real example is a bit more complicated. I have Contacs (instead of Persons), which have differen buyinginterests (for example services).
Code:
Criteria crit = _session.createCriteria(Contact.class, "con");
DetachedCriteria buy =
DetachedCriteria.forClass(Contact.class, "dc")
.createAlias("buyinginterest", "buyinginterest")
.add(Restrictions.eq("buyinginterest.name", "services"))
.setProjection(Projections.id());
crit.createAlias("buyinginterest", "buyinginterest");
crit.add(Subqueries.notExists(buy));
Generated SQL:
select ...... where not exists (select this0__.id as y0_ from contact this0__ where buyinginte1_.name=?)
Code:
Criteria crit = _session.createCriteria(Contact.class, "con");
DetachedCriteria buy =
DetachedCriteria.forClass(Buyinginterest.class, "dc")
.add(Restrictions.eq("dc.name", "services"))
.setProjection(Projections.id());
crit.createAlias("buyinginterest", "buyinginterest");
crit.add(Subqueries.propertyNotIn("buyinginterest" ,buy));
Generated SQL Statement:
where this_.id not in (select this0__.id as y0_ from buyinginterest this0__ where this0__.name=?)
The entity classes:
Code:
@Entity
@Table(name = "contact")
public class Contact implements Serializable, Comparable<Contact> {
private static final long serialVersionUID = 1L;
@Id
@Column(name="id")
@GeneratedValue
private int id;
...
...
...
@ManyToMany
@JoinTable(name="contact_buyinginterest", joinColumns = @JoinColumn(name="contact_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name="buyinginterest_id", referencedColumnName = "id"))
private List<Buyinginterest> buyinginterest;
}
Code:
@Entity
@Table(name="buyinginterest")
public class Buyinginterest implements Serializable {
@Id
private int id;
@Lob
private String description;
private String name;
private static final long serialVersionUID = 1L;
public Buyinginterest() {
super();
}
Thanks very much for help![/code]