mandubian/siena — Issue #9: Classes maintaining relationships with Abstract Classes throw Instantiation Exception
Author: OuchMyHead
Created: 2011-10-24 19:37:27+00:00
State: open

This bug occured using Siena and GAE within the Play! Framework 1.2.3

When instantiating objects from the database, an Instantiation Exception is thrown if the persisted object references an abstract class.

For example:

************** Abstract Class **************

public abstract class Post extends Model {

//default constructor
public Post(){

}

@Id(Generator.AUTO_INCREMENT)
public long id;

@Filter("post")
public Query comments;

public static Query all() {
return Model.all(Post.class);
}

public static Post findById(long id) {
return all().filter("id", id).get();
}

public Comment addComment( String s_comment ){
Comment comment = new Comment( this, s_comment );
return comment;
}

public List comments() {
return comments.order().fetch();
}

}

************** Inhertiting Class **************

@Table("post_pics")
public class Post_Pic extends Post {

//default constructor
public Post_Pic(){

}

@Column("post")
@Index("post_index")
public Post post;

public String path;
public String description;

}

************** Class Referencing Post **************

@Table("comments")
public class Comment extends Model {

@Id(Generator.AUTO_INCREMENT)
public long id;

@Column("post")
@Index("post_index")
public Post post;

public String comment;

public static Query 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 Code **************

@Test
public void commentPost_Pic(){

Post_Pic post_pic = new Post_Pic();
post_pic.insert();
Comment comment = post_pic.addComment( testComment );
comment.insert();

comment = Comment.findById( comment.id ); //**** <- Error gets thrown here

}

****************** End of Code ******************

An Instantiation Exception is thrown when comment is instantiated from the database.