0

I made a inner-join between two tables, but it isn't working. It would help me a lot, if someone could help me as soon as possible.

Thanks in advance

It looks like this:

List<Bondetal> bondetals = session.createQuery("from Bondetal bd inner join bd.Bon b where bd.idbon = b.idbon and idprodus = " + idprodus +" and Bon.suma >=" + suma).list();

I get this error:

Exception in thread "AWT-EventQueue-0" org.hibernate.QueryException: could not resolve property: Bon of: sakila.entity.Bondetal [from sakila.entity.Bondetal bd inner join bd.Bon b where bd.idbon = b.idbon and idprodus = 2 and Bon.suma >=1]
alin
  • 145
  • 1
  • 2
  • 11

1 Answers1

0

To be able to make a join, you need an association between the entities. The BonDetal entity should thus have something like

@ManyToOne
@JoinColumn(name = "idbon")
private Bon bon;

It must not have any idbon property, since the idbon column is mapped by the association.

And the query doesn't need any where bd.idbon = b.idbon clause, since Hibernate knows how the entities are associated with each other. The query should thus be:

select bd from Bondetal bd 
inner join bd.bon b 
where bd.idprodus = :idprodus 
and b.suma >= :suma

You also should use named parameters rather than concatenating values to the query, to avoid SQL injection attacks and escaping problems.

All of this is explained in the Hibernate documentation. If you're in such a hurry, you should read it instead of trying random queries.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • It works. You helped me a lot! and I really appreciate it. :) I tried to read from that documentation, but I didn't understand very good from there. Anyway you're my hero!! – alin Jun 21 '12 at 21:55