Java GAE&;Siena-抽象类和实例化异常
我正在使用Play构建我的第一个GAE应用程序!框架,我对Siena和抽象类有问题 应用程序中的一个功能是允许用户上传帖子,其他用户可以对其发表评论。然而,当我试图创建多个从抽象Java GAE&;Siena-抽象类和实例化异常,java,google-app-engine,playframework,siena,Java,Google App Engine,Playframework,Siena,我正在使用Play构建我的第一个GAE应用程序!框架,我对Siena和抽象类有问题 应用程序中的一个功能是允许用户上传帖子,其他用户可以对其发表评论。然而,当我试图创建多个从抽象post类继承的post类型时,我遇到了问题 Post类和相应的Picture子类定义如下: @Test public void commentPost_Pic(){ User bob = new User( fullname, email, password ); bob.insert(); b
post
类继承的post类型时,我遇到了问题
Post
类和相应的Picture
子类定义如下:
@Test
public void commentPost_Pic(){
User bob = new User( fullname, email, password );
bob.insert();
bob = User.connect( email, password );
assertNotNull( bob );
Post_Pic post_pic = new Post_Pic();
post_pic.insert();
Comment comment = post_pic.addComment( bob, testComment );
comment.insert();
List<Comment> comments = post_pic.comments(); //**** <- Error gets thrown here
assertEquals( 1, comments.size() );
}
职位
以及相应的
注释
类:
评论
InstantiationException
在List comments=post_pic.comments()行抛出代码>尝试在模型中创建默认构造函数。。。
Siena使用反射创建类,但它不尝试使用特定的构造函数!
告诉我它是否工作得更好 谢谢你的回复。不幸的是,我已经试过了,正如我看到的(我认为你是帕斯卡对吗?)。我将结束我的代码以显示抛出错误的测试。好的,抽象类可能有问题。这个案例没有单元测试,所以我不能说它是否有效!如果您可以在上打开一个带有代码示例和错误的问题,那就太好了。我会尽快修补它!好的,谢谢你在Github上的回复。如果您不介意发布一个链接到您的Github回复,那么我很乐意将此作为可接受的答案!以下是我对github的评论,解释了这个问题:
public class Picture extends Post {
//***EDIT*** - added default constructor
public Post_Pic(){
}
public String path;
public String description;
}
public class Comment extends Model {
@Id(Generator.AUTO_INCREMENT)
public long id;
@Index("post_index")
public Post post;
public String comment;
public static Query<Comment> all() {
return Model.all(Comment.class);
}
public static Comment findById(long id) {
return all().filter("id", id).get();
}
public Comment( Post post, String comment ){
this.post = post;
this.comment = comment;
}
}
@Test
public void commentPost_Pic(){
User bob = new User( fullname, email, password );
bob.insert();
bob = User.connect( email, password );
assertNotNull( bob );
Post_Pic post_pic = new Post_Pic();
post_pic.insert();
Comment comment = post_pic.addComment( bob, testComment );
comment.insert();
List<Comment> comments = post_pic.comments(); //**** <- Error gets thrown here
assertEquals( 1, comments.size() );
}