Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java play framework 2.2:如何定义ebean多人查询_Java_Sql_Playframework_Ebean_Playframework 2.2 - Fatal编程技术网

Java play framework 2.2:如何定义ebean多人查询

Java play framework 2.2:如何定义ebean多人查询,java,sql,playframework,ebean,playframework-2.2,Java,Sql,Playframework,Ebean,Playframework 2.2,我试图在Play2.0中实现Play1.0中的yabe教程 目前我被标签功能卡住了: 本质上,问题在于: 我有一个Post类,每个Post对象可以有多个与该类关联的标记: @ManyToMany(cascade=CascadeType.PERSIST) public Set<Tag> tags; 我目前的执行情况如下: @Test public void testTags() { // Create a new user and save it SuperU

我试图在Play2.0中实现Play1.0中的yabe教程

目前我被标签功能卡住了:

本质上,问题在于:

我有一个Post类,每个Post对象可以有多个与该类关联的标记:

@ManyToMany(cascade=CascadeType.PERSIST)
public Set<Tag> tags;
我目前的执行情况如下:

    @Test
public void testTags() {
    // Create a new user and save it
    SuperUser.setInstance("bob@gmail.com", "secret", "Bob").save();

    SuperUser bob = SuperUser.getInstance();

    // Create a new post
    Post bobPost = new Post(bob, "Hello world","My first post");
    bobPost.save();

    Post anotherBobPost = new Post(bob, "Hello world", "Hop");
    anotherBobPost.save();

    // Well
    assertEquals(0, Post.findTaggedWith("Red").size());

    // Tag it now
    bobPost.tagItWith("Red").tagItWith("Blue").save();
    anotherBobPost.tagItWith("Red").tagItWith("Green").save();

    // Check
    assertEquals(2, Post.findTaggedWith("Red").size());
    assertEquals(1, Post.findTaggedWith("Blue").size());
    assertEquals(1, Post.findTaggedWith("Green").size());

    // Checks for multiple tag params
    assertEquals(1, Post.findTaggedWith("Red", "Blue").size()); //Fail -  Actual: 0
    assertEquals(1, Post.findTaggedWith("Red", "Green").size());
    assertEquals(0, Post.findTaggedWith("Red", "Green", "Blue").size());
    assertEquals(0, Post.findTaggedWith("Green", "Blue").size());

    SuperUser.removeSuperUser();

}
    public static List<Post> findTaggedWith(String... tags) {

    ExpressionList<Post> expAcc = Post.find.fetch("tags").where().conjunction();

    for( String tag : tags){

        expAcc = expAcc.eq("tags.name", tag);

    }

    return expAcc.endJunction().findList();
}
公共静态列表findTaggedWith(字符串…标记){
ExpressionList expAcc=Post.find.fetch(“标记”).where().conjunction();
用于(字符串标记:标记){
expAcc=expAcc.eq(“tags.name”,tag);
}
返回expAcc.endJunction().findList();
}
我不知道下一步该怎么办,因为我是野蛮人,强迫这样做却一事无成:(


谢谢!

尝试打开EBean SQL日志。查看EBean正在执行的SQL语句非常有用


请参见

尝试打开EBean SQL日志。查看EBean正在执行的SQL语句非常有用


你真的很亲密。问题在于你的关系。你想在你的
博文
课程中得到的是:

@OneToMany(cascade=CascadeType.PERSIST, mappedBy = "post")
public Set<Tag> tags;
根据DB模式与模型类的匹配程度,您可能需要也可能不需要尝试添加
@JoinColumn
注释


这显示了预期的关系。
Post模型中的一(Post)对多(Tags)
,Tag模型中的多(Tags)对一(Post)。

你真的很亲密。问题在于你的关系。你想在
Post
类中得到的是:

@OneToMany(cascade=CascadeType.PERSIST, mappedBy = "post")
public Set<Tag> tags;
根据DB模式与模型类的匹配程度,您可能需要也可能不需要尝试添加
@JoinColumn
注释


这显示了预期的关系。
One(Post)to Many(Tags)
在Post模型中,
Many(Tags)to One(Post)
在Tag模型中。

解决方案有什么问题?函数返回的列表为空解决方案有什么问题?函数返回的列表为空