Assume that there is a Model bean with a unique contraint combining two columns (as composite primary keys) like this:
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "key1", "key2" }) })
public class Rating extends Model {
@ManyToOne
@JoinColumn(name="key1", nullable=false)
public Post key1;
@ManyToOne
@JoinColumn(name="key2", nullable=false)
public User key2;
...
}
How can i find a finder for the method with the following signature:
public static Rating get(Post key1, User key2) { ... }
AFAIK, you’re not defining a composite key, but just an unique constraint between two properties. To define a composite key, you have to use the
@EmbeddedId[1] or@IdClass[2] annotations.I’ll go with
@EmbeddedId, you can see an example of use here: http://weblogs.java.net/blog/bleonard/archive/2006/11/using_composite.html