How do I write this JPA query that requires a JOIN?
I'm using JPA 2.0, Hibernate 4.1.0.Final, and Spring 3.1.1.RELEASE. I have
two entities:
@Entity
@Table(name = "user",
uniqueConstraints = { @UniqueConstraint(columnNames = { "USER_NAME" }) }
)
public class User implements Comparable<User>, Serializable
{
...
@Column(name = "first_name")
@NotNull
/* the first name of the User */
private String firstName;
and
@Entity
@Table(name="code_user",
uniqueConstraints = {
@UniqueConstraint(columnNames = { "SAMPLE_WORD_ID", "USER_ID" }) }
)
public class CodeUser
{
@Id
@NotNull
@GeneratedValue(generator = "uuid-strategy")
@Column(name = "ID")
private String id;
@ManyToOne
@JoinColumn(name = "CODE_ID", nullable = false, updatable = true)
private Code code;
@ManyToOne
@JoinColumn(name = "USER_ID", nullable = false, updatable = true)
private User user;
How do I write a JPA/CriteriaBuilder query to find all User objects who's
first name matches "Dave" and who are tied to a Code record in which the
code is "abode"?
No comments:
Post a Comment