-
-
2. Re: BUG?
seto Oct 31, 2006 8:32 AM (in response to seto)No, I means that the resultlist return null, but not the field
-
3. Re: BUG?
monkeyden Oct 31, 2006 8:38 AM (in response to seto)so when a single number field is null, the whole resultlist is null?
-
-
5. Re: BUG?
seto Oct 31, 2006 9:31 AM (in response to seto)You can have a test in your enviroment. I have tried it for times. I finally catch this problem
-
6. Re: BUG?
seto Oct 31, 2006 6:16 PM (in response to seto)No one can answer me? I'm in trouble with this problem for long.
-
7. Re: BUG?
jazir1979 Oct 31, 2006 9:31 PM (in response to seto)"Seto" wrote:
No one can answer me? I'm in trouble with this problem for long.
Try the EJB3 or Hibernate forum.
Post your whole query to one of those forums. I suspect you may be doing "= null" in your where clause instead of "is null"? -
8. Re: BUG?
seto Nov 1, 2006 12:03 AM (in response to seto)In Article.java
@Column(name = "click_count")
private int click_count;
And the SQL is just "from Article article"
When the click_count is null in the database, the resultlist return null. When the click+count is 0 in the databse, the resultlist is normal.
So I judged it the problem of null int filed. -
9. Re: BUG?
monkeyden Nov 1, 2006 10:20 AM (in response to seto)The @Column annotation goes on the accessor, not the data member. I have also gotten back a List whose count was > 0, even though everything was null. I assume this was happening because the primary key field I was using wasn't actually primary key worthy (i.e. unique). Created a surrogate field and it worked fine.
-
10. Re: BUG?
pmuir Nov 1, 2006 10:37 AM (in response to seto)"monkeyden" wrote:
The @Column annotation goes on the accessor, not the data member.
@Column can go either the field or the accessor - check it's @Target/documentation
I'm assuming this thread is about a database table rather than a table in the presentation tier. If so, this is certainly the wrong forum, you would get more help in the hibernate forum. -
11. Re: BUG?
monkeyden Nov 1, 2006 10:56 AM (in response to seto)@Column can go either the field or the accessor
You are correct. My mistake.I'm assuming this thread is about a database table rather than a table in the presentation tier
Me too, but this symptom is also in line with an inadequate @Id field in the entity, as was the case for me. -
12. Re: BUG?
seto Nov 3, 2006 4:20 AM (in response to seto)here is the code of the Article
/** * */ package cn.net.kdc.domain.cms; import java.util.*; import javax.persistence.*; import org.hibernate.validator.*; import cn.net.kdc.domain.global.*; /** * @author Seto * */ @Entity @Table(name = "cms_article") public class Article { @Id @GeneratedValue @Column(name = "id") private int id; @Column(name = "tag") @NotNull @Length(min = 2, max = 8) private String tag; @Column(name = "title") @NotNull @Length(min = 4, max = 32) private String title; @Column(name = "short_title") @NotNull @Length(min = 4, max = 32) private String short_title; @Column(name = "long_title") @NotNull @Length(min = 4, max = 32) private String long_title; @Column(name = "author") @Length(min = 4, max = 64) private String author; @Column(name = "click_count") private int click_count; @Column(name = "insert_date") @NotNull @Temporal(TemporalType.TIME) private Date insert_date = new Date(); @Column(name = "update_date") @NotNull @Temporal(TemporalType.TIME) private Date update_date = new Date(); @Column(name = "intro") private String intro; @Column(name = "content") @NotNull private String content; @ManyToOne @JoinColumn(name = "photo") private Resource photo = new Resource(); @ManyToOne @JoinColumn(name = "position") private Position position = new Position(); @ManyToOne @JoinColumn(name = "category") private Category category = new Category(); @ManyToMany @JoinTable(name = "cms_area_article", joinColumns = { @JoinColumn(name = "article") }, inverseJoinColumns = { @JoinColumn(name = "area") }) private List<Area> areas = new ArrayList<Area>(); @OneToMany(mappedBy = "article") private List<Comment> comments = new ArrayList<Comment>(); /** * default constuctor */ public Article() { super(); } /** * minimal constructor * * @param id * @param tag * @param title * @param short_title * @param long_title * @param insert_date * @param update_date * @param content * @param position * @param category */ public Article(int id, String tag, String title, String short_title, String long_title, Date insert_date, Date update_date, String content, Position position, Category category) { super(); this.id = id; this.tag = tag; this.title = title; this.short_title = short_title; this.long_title = long_title; this.insert_date = insert_date; this.update_date = update_date; this.content = content; this.position = position; this.category = category; } /** * full constructor * * @param id * @param tag * @param title * @param short_title * @param long_title * @param author * @param click_count * @param insert_date * @param update_date * @param intro * @param content * @param photo * @param position * @param category * @param areas * @param comments */ public Article(int id, String tag, String title, String short_title, String long_title, String author, int click_count, Date insert_date, Date update_date, String intro, String content, Resource photo, Position position, Category category, List<Area> areas, List<Comment> comments) { super(); this.id = id; this.tag = tag; this.title = title; this.short_title = short_title; this.long_title = long_title; this.author = author; this.click_count = click_count; this.insert_date = insert_date; this.update_date = update_date; this.intro = intro; this.content = content; this.photo = photo; this.position = position; this.category = category; this.areas = areas; this.comments = comments; } /** * @return the id */ public int getId() { return id; } /** * @param id * the id to set */ public void setId(int id) { this.id = id; } /** * @return the tag */ public String getTag() { return tag; } /** * @param tag * the tag to set */ public void setTag(String tag) { this.tag = tag; } /** * @return the title */ public String getTitle() { return title; } /** * @param title * the title to set */ public void setTitle(String title) { this.title = title; } /** * @return the short_title */ public String getShort_title() { return short_title; } /** * @param short_title * the short_title to set */ public void setShort_title(String short_title) { this.short_title = short_title; } /** * @return the long_title */ public String getLong_title() { return long_title; } /** * @param long_title * the long_title to set */ public void setLong_title(String long_title) { this.long_title = long_title; } /** * @return the author */ public String getAuthor() { return author; } /** * @param author * the author to set */ public void setAuthor(String author) { this.author = author; } /** * @return the click_count */ public int getClick_count() { return click_count; } /** * @param click_count * the click_count to set */ public void setClick_count(int click_count) { this.click_count = click_count; } /** * @return the insert_date */ public Date getInsert_date() { return insert_date; } /** * @param insert_date * the insert_date to set */ public void setInsert_date(Date insert_date) { this.insert_date = insert_date; } /** * @return the update_date */ public Date getUpdate_date() { return update_date; } /** * @param update_date * the update_date to set */ public void setUpdate_date(Date update_date) { this.update_date = update_date; } /** * @return the intro */ public String getIntro() { return intro; } /** * @param intro * the intro to set */ public void setIntro(String intro) { this.intro = intro; } /** * @return the content */ public String getContent() { return content; } /** * @return the photo */ public Resource getPhoto() { return photo; } /** * @param photo * the photo to set */ public void setPhoto(Resource photo) { this.photo = photo; } /** * @param content * the content to set */ public void setContent(String content) { this.content = content; } /** * @return the position */ public Position getPosition() { return position; } /** * @param position * the position to set */ public void setPosition(Position position) { this.position = position; } /** * @return the category */ public Category getCategory() { return category; } /** * @param category * the category to set */ public void setCategory(Category category) { this.category = category; } /** * @return the areas */ public List<Area> getAreas() { return areas; } /** * @param areas * the areas to set */ public void setAreas(List<Area> areas) { this.areas = areas; } /** * @return the comments */ public List<Comment> getComments() { return comments; } /** * @param comments * the comments to set */ public void setComments(List<Comment> comments) { this.comments = comments; } }
here is the table definitionCREATE TABLE `cms_article` ( `id` int(10) unsigned NOT NULL auto_increment, `tag` varchar(8) NOT NULL, `title` varchar(32) NOT NULL, `short_title` varchar(32) NOT NULL, `long_title` varchar(32) NOT NULL, `author` longtext, `click_count` int(10) unsigned default NULL, `insert_date` datetime NOT NULL, `update_date` datetime NOT NULL, `intro` longtext, `content` longtext NOT NULL, `photo` int(10) unsigned default NULL, `position` int(10) unsigned NOT NULL, `category` int(10) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
here is the HQL stringsfrom Article article
Result:
The row with null click_count won't return.