Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.2.2
Mapping documents:
Code:
<hibernate-mapping ..>
<list name="comments" table="comment" cascade="all>
<key column="a_id" />
<list-index column="id" />
<one-to-many class="Comment" />
</list>
</hibernate-mapping>
Hi, I'm newbie studying hibernate.
I'm trying to make a simple web application. There are articles with comments. As I think that one article should have multiple comments, I use list collection.
in my Database(Mysql 5) there are only two tables.
one is Article
another is Comment
field "a_id" of Comment is references of field "id" of Article
when my WAS responses to show article
Code:
public static Article getArticle(int id) {
Session ses = HibernateUtil.currentSession();
Article a = (Article)ses.get(Article.class, id);
return a;
}
this code invokes setter of comments in Article class
Code:
public void setComments(List<Comment> comments) {
this.comments = comment;
}
but I saw a NullPointerException, using Article.getComment();
so I wanna find why?
in the list(Article.comments), there should be 2 objects because there are 2 comments in the database!!
but it has 3 objects, and the first one is null; 2nd, 3rd are correct.
How can I correct this problem?
is it bug? or not?