alesj wrote:
Sure.
Why not?
Have you had any problems?
Hi alesj
Yes, I have problems. It seams that the join conditions (a.id = ab.id.id_a, ab.id.id_b = b.id) are the problem.
Have you any suggestion?
A JAVA classes are these:
--------- A -------------
import java.util.*;
import javax.persistence.*;
@Entity
@Table(name = "A")
@NamedQueries({
	@NamedQuery(name="getAByParameters",
	            query="SELECT OBJECT(a)
	                     FROM A  AS a,
	                          AB AS ab,
	                          B  AS b
	                    WHERE a.id = ab.id.id_a
	                      AND ab.id.id_b = b.id
	                      AND b.name like :p_name")
})
public class A implements java.io.Serializable {
	private static final Logger log = Logger.getLogger(A.class);
	private int id;
	private Date date;
	private Collection<B> bs = new ArrayList<B>(0);
	public A() {
	}
	public A(int id,
                   Date date) {
		this.id = id;
	}
	public A(int id,
                   Date date,
	               Collection<b> p_bs) {
		this.id = id;
		this.date = date;
		this.bs = p_bs;
	}
	@Id
	@Column(name="ID")
	public int getId() { return this.id; }
	public void setId(int id) { this.id = id; }
	@Column(name="DATE")
	public Date getDate() { return this.date; }
	public void setDate(Date date) { this.date = date; }
    @ManyToMany
    @JoinTable(name="AB",
               joinColumns={@JoinColumn(name="id_a")},
               inverseJoinColumns={@JoinColumn(name="id_b")}
              )
	public Collection<B> getBs() { return this.bs; }
	public void setBs(Collection<B> p_bs) { this.bs = p_bs; }
}
-------------- AB -----------------
import java.util.*;
import javax.persistence.*;
@Entity
@Table(name = "AB")
public class AB implements java.io.Serializable {
	private ABId id;
	public AB() {
	}
	public AB(ABId id) {
		this.id = id;
	}
	@EmbeddedId
	public ABId getId() { return this.id; }
	public void setId(ABId id) { this.id = id; }
}
------------------- ABId ------------
import javax.persistence.*;
@Embeddable
public class ABId implements java.io.Serializable {
	private int id_a;
	private int id_b;
	public ABId() {
	}
	public ABId(int id_a, int id_b) {
		this.id_a = id_a;
		this.id_b = id_b;
	}
	@Column(name="ID_A")
	public int getId_a() { return this.id_a; }
	public void setId_a(int id_a) { this.id_a = id_a; }
	@Column(name="ID_B")
	public int getId_b() { return this.id_b; }
	public void setId_b(int id_b) { this.id_b = id_b; }
	public boolean equals(Object other) {
		if ( (this == other ) ) return true;
		if ( (other == null ) ) return false;
		if ( !(other instanceof ABId) ) return false;
		ABId castOther = ( ABId ) other;
		return (this.getId_a()==castOther.getId_a())
            && (this.getId_b()==castOther.getId_b());
	}
	public int hashCode() {
		int result = 17;
		result = 37 * result + this.getId_a();
		result = 37 * result + this.getId_b();
		return result;
	}
}
--------------------- B -----------------------
import java.util.*;
import javax.persistence.*;
@Entity
@Table(name = "B")
public class B implements java.io.Serializable {
	private int id;
	private String name;
	private Collection<A> as = new ArrayList<A>(0);
    public B() {
    }
    public B(int id,
                 String name) {
        this.id = id;
        this.name = name;
    }
    public B(int id,
                 String name,
	             Collection<A> as) {
       this.id = id;
       this.name = name;
       this.as = as;
    }
	@Id
	@Column(name="ID")
	public int getId() { return this.id; }
	public void setId(int id) { this.id = id; }
	@Column(name="name")
	public String getName() { return this.name; }
    public void setName(String name) { this.name = name; }
    @ManyToMany
    @JoinTable(name="AB",
               joinColumns={@JoinColumn(name="id_b")},
               inverseJoinColumns={@JoinColumn(name="id_a")}
              )
	public Collection<A> getAs() { return this.as; }
	public void setAs(Collection<A> as) { this.as = as; }
}