6 Replies Latest reply on Nov 3, 2006 8:21 AM by seto

    Bug of Persistence API?

    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.

      I mean that the whole resultlist return null when the click_count is null.

      So I judged it the problem of null int field. I'm in trouble with the problem for long. Appreciate your answers.

        • 1. Re: Bug of Persistence API?
          alexg79

          Could you explain what the problem here is? I don't see any getters or setters there either. What do they look like?

          • 2. Re: Bug of Persistence API?
            monkeyden

            Yes, post the entity code, the snippet executing the query and the table definition.

            • 3. Re: Bug of Persistence API?
              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 definition
              CREATE 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 strings
              from Article article
              


              Result:
              The row with null click_count won't return.

              • 4. Re: Bug of Persistence API?
                vlumi

                I would use Integer instead of int as the field's type, as only objects can be null.

                • 5. Re: Bug of Persistence API?
                  seto

                  oh, thanks I try it.

                  • 6. Re: Bug of Persistence API?
                    seto

                    OK, the result is normal, thanks a lot.
                    But I also have a problem, I change the type to Integer, result is normal.
                    When I change it back, it reports exception, but it doesn't before.