Note that there are some explanatory texts on larger screens.

plurals
  1. POHQL Problem
    primarykey
    data
    text
    <p>Hi every one I have these classe</p> <pre><code>@Entity @Table(name = "login", uniqueConstraints={@UniqueConstraint(columnNames={"username_fk"})}) public class Login implements Serializable { @Id @Column(name = "id") @GeneratedValue private int id; @Column(name = "password", length = 64) private String password; @Column(name = "roles", length = 32) private String roles; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @OnDelete(action=OnDeleteAction.CASCADE) @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) @JoinColumn(name = "username_fk", nullable=false) private Branch branch; //some getter and sette </code></pre> <p>and </p> <pre><code>@Entity @Table(name = "branch", uniqueConstraints = {@UniqueConstraint(columnNames = {"bname", "branch_fk"})}) public class Branch implements Serializable { @Id @GeneratedValue private int id; @Column(name = "username", length = 64, nullable=false) private String userName; @Column(name = "bname", length = 64) private String branchName; @Column(name = "officername", length = 64) private String officerName; @Column(name = "studcount") private int studCount; @Column(name = "blevel", columnDefinition="int default 0") private int level; @Column(name = "officeremail", length = 64) private String officerEmail; @Column(name = "confirmed", columnDefinition = "tinyint default 0") private int confirmed; @OneToOne(mappedBy = "branch", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @OnDelete(action=OnDeleteAction.CASCADE) @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) private Login login; </code></pre> <p>when i use this Query :</p> <pre><code>executeQuery("select l from Login as l inner join l.branch as b where l.branch.bname = ?", username) </code></pre> <p>or this:</p> <pre><code>executeQuery("select b.login from Branch b where b.username = ?", username) </code></pre> <p>I have get this error:</p> <pre><code>org.hibernate.QueryException: could not resolve property: bname of: Data.Entity.Branch </code></pre> <p>but when use this code:</p> <pre><code>executeQuery("select b.login from Branch b where b.id = ?", username) it's return correct result </code></pre> <p>I means this type of HQL just work for Primary key? or my maping have problem? is there any way that I can use other field(except Primary Key) form joinable table?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload