jpa merge谓词数组+搜索外键值

时间:2015-10-02 09:46:08

标签: jpa

我希望有这样的搜索:

$(function () {
    $('#search-bar').on('submit', function (e) {
        var y = $('#search').val().toLowerCase();
        if (y === 'location') {
            geoSearch();
        } else {
        qCall(y);
        }
        x.val('');
        e.preventDefault;
    });
});

我将2个谓词组合成一个数组,但只需要1个谓词

Select * From Users where ( ( username Like %criteria% OR firstName Like %criteria% ...) AND (CarId = carId) ) 

Car是一个类似的类,User有1个外键。

@Entity
@Table(name = "users", uniqueConstraints = { @UniqueConstraint(columnNames = { "username" }) })
public class User{
@Id
@GeneratedValue(generator = "seq_id_user", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "seq_id_user", sequenceName = "seq_id_user")
private Long id;
@Column(unique = true)
@NotNull
private String username;
@Column(name = "first_name")
private String firstName;
....
@ManyToOne
@JoinColumn(name = "car_id", nullable = false, foreignKey = @ForeignKey(name = "CAR_ID_FK"))
private Car car;
...

0 个答案:

没有答案