Java Ebean在查询中使用和

Java Ebean在查询中使用和,java,mysql,playframework,ebean,Java,Mysql,Playframework,Ebean,我正在尝试进行一个查询,其中我想检查帐户信息是否处于活动状态(boolean=True)以及该用户的帐户信息(来自模型的userid)。在SQL中,我会像 Select * from mst_account where user=1 and active = 1 我想使用Ebean in-play框架来实现这一点 如何使用ebean编写这样的查询 用户帐户的模型如下所示 @Table(name="mst_user_account") public class UserAccount

我正在尝试进行一个查询,其中我想检查帐户信息是否处于活动状态(boolean=True)以及该用户的帐户信息(来自模型的userid)。在SQL中,我会像

Select * from mst_account where user=1 and active = 1
我想使用Ebean in-play框架来实现这一点

如何使用ebean编写这样的查询

用户帐户的模型如下所示

    @Table(name="mst_user_account")

public class UserAccount extends Model {
    @Id
    public Long id;

    public String email="";

    public String username="";

    public String password="";

    @Formats.DateTime(pattern = "yyyy-MM-dd hh:mm:ss")
    public Date createdOn=new Date();

    @Formats.DateTime(pattern="yyyy-MM-dd hh:mm:ss")
    public Date activatedOn;

    public String activationCode="";


    public Boolean activationStatus=false;

    public Boolean accountStatus=false;

    @ManyToOne
    public Roles role;



    public static Finder<Long,UserAccount> find=new Finder<Long,UserAccount>(Long.class,UserAccount.class);

    public static UserAccount findByEmail(String email){

        return UserAccount.find.where().eq("email",email).findUnique();
    }


    public static UserAccount findByUsername(String username){

        return UserAccount.find.where().eq("username",username).findUnique();

    }

    public static UserAccount findByActivationCode(String code){
        return UserAccount.find.where().eq("activationCode",code).findUnique();
    }


    public static UserAccount authenticate(String username,String password){
        return UserAccount.find.where().eq("username",username).eq("password",password).findUnique();
    }

//mod seroney to take care of display of username----
    public static UserAccount isLoggedIn() {
        String uuid = session("id");
        UserAccount user = UserAccount.find.byId(Long.parseLong(uuid));
        return user;


    }
@Table(name=“mst\U用户\U帐户”)
公共类UserAccount扩展模型{
@身份证
公共长id;
公共字符串email=“”;
公共字符串用户名=”;
公共字符串密码=”;
@格式.日期时间(pattern=“yyyy-MM-dd hh:MM:ss”)
public Date createdOn=新日期();
@格式.日期时间(pattern=“yyyy-MM-dd hh:MM:ss”)
公开日期激活;
公共字符串activationCode=“”;
public Boolean activationStatus=false;
public Boolean accountStatus=false;
@许多酮
公共角色;
publicstaticfinder=newfinder(Long.class,UserAccount.class);
公共静态用户帐户findByEmail(字符串电子邮件){
返回UserAccount.find.where().eq(“email”,email).findUnique();
}
公共静态用户帐户findByUsername(字符串用户名){
返回UserAccount.find.where().eq(“用户名”,username.findUnique();
}
公共静态用户帐户FindByaActivationCode(字符串代码){
返回UserAccount.find.where().eq(“activationCode”,code).findUnique();
}
公共静态用户帐户身份验证(字符串用户名、字符串密码){
返回UserAccount.find.where().eq(“用户名”,用户名).eq(“密码”,密码).findUnique();
}
//mod seroney负责用户名的显示----
公共静态用户帐户isLoggedIn(){
字符串uuid=会话(“id”);
UserAccount user=UserAccount.find.byId(Long.parseLong(uuid));
返回用户;
}
会计模型

@Entity
@Table(name="mst_account")
public class Account extends Model {
    @Id
    public Long id;

    public String firstName="";

    public String surname = "";

    public String otherName="";

    public String address="";

    public String city="";

    public String country="";

    public String mobile="";

    public String zipcode="";

    public String stateprv ="";

    public String usrtimezone ="";

    public Boolean physicalDisability =false;

    public String physicalDisabilityDesc ="";

    @OneToOne
    public ModeOfStudy modeOfStudy;

    @OneToOne
    public Campus campus;

    @OneToOne
    public CourseMst course;

    public String hschatt ="";

    public String hsgpa ="";

    public Qualifications hschyr;

    public String unvatt ="";

    public String ungpa ="";

    public Qualifications unvyr;

    public Boolean isprocessed = false;

    public Boolean isapproved = false;

    public Boolean isPosted = false;

    @Formats.DateTime(pattern = "yyyy-MM-dd hh:mm:ss")
    public Date createdOn=new Date();

    @OneToOne
    public UserAccount user;
    @OneToOne
    public UserAccount isapprovedby;


    public static Finder<Long,Account> find=new Finder<Long,Account>(Long.class,Account.class);

    public static Account findByMobile(String mob){

        return Account.find.where().eq("mobile",mob).findUnique();
    }

    public static Account findByAltPhone(String phone){

        return Account.find.where().eq("alternatePhone",phone).findUnique();
    }

    public static Account findByCardNumber(String card){

        return Account.find.where().eq("cardNumber",card).findUnique();

    }


    public static Account findByUserId(Long user){

        return find.where().eq("user", user).eq("isPosted", true).findUnique();
    }


}
@实体
@表(name=“mst\U账户”)
公共类帐户扩展模型{
@身份证
公共长id;
公共字符串firstName=“”;
公共字符串姓氏=”;
公共字符串otherName=“”;
公共字符串地址=”;
公共字符串城市=”;
公共字符串country=“”;
公共字符串mobile=“”;
公共字符串zipcode=“”;
公共字符串stateprv=“”;
公共字符串usrtimezone=“”;
公共布尔物理残疾=假;
公共字符串physicalDisabilityDesc=“”;
@奥内托内
公共研究模式;
@奥内托内
公共校园;
@奥内托内
公共课程;
公共字符串hschatt=“”;
公共字符串hsgpa=“”;
公共资格证书;
公共字符串unvatt=“”;
公共字符串ungpa=“”;
公共资格;
公共布尔值isprocessed=false;
公共布尔值isapproved=false;
公共布尔值isPosted=false;
@格式.日期时间(pattern=“yyyy-MM-dd hh:MM:ss”)
public Date createdOn=新日期();
@奥内托内
公共用户帐户用户;
@奥内托内
公共用户帐户已被批准;
publicstaticfinder=newfinder(Long.class、Account.class);
公共静态帐户findByMobile(字符串移动){
返回Account.find.where().eq(“mobile”,mob.findUnique();
}
公共静态帐户findByAltPhone(字符串电话){
return Account.find.where().eq(“alternatePhone”,phone.findUnique();
}
公共静态帐户findByCardNumber(字符串卡){
返回Account.find.where().eq(“卡号”,card.findUnique();
}
公共静态帐户findByUserId(长用户){
返回find.where();
}
}

我正在尝试检查用户是否已将数据发布到mst帐户

将以下代码片段放入您的帐户模型中。我将模型名称用作
帐户
替换您自己的模型名称

public static Finder<Long,Account> find = new Finder(Long.class, Account.class);

public static Account findByUserID(int user_id){
    return find.where().eq("user", user_id).eq("active", true).findUnique();
}

我的用户id很长。现在我在/media/seroney/Stuff/Projects/java/Play FrameWork/Codi/app/models/Account.java:104 101}102公共静态帐户findByUserId(Long userid){103 104 return find.where().eq(“用户”,userid.eq(“isPosted”)中得到了一个错误[RuntimeException:get-id on-on[models.UserAccount]type[java.lang.lang.Long]抛出了错误],true).findUnique();105}@Seroney你能发布你的模型吗?添加了模型,但它正在等待同行评审发布了模型,最初编辑了你的答案对不起。
 public static Account findByUserId(Long user){
    return find.where().eq("user.id", user).eq("isPosted", true).findUnique();
}