-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: parent-children table parentId could not set int to null why
PostPosted: Mon Nov 19, 2007 11:27 am 
Newbie

Joined: Tue Jun 26, 2007 10:04 pm
Posts: 4
when i try to save a entity , it said:
Code:
QueryEntry qe = new QueryEntry();
      qe.setTitle("test");
      queryEntryDAO.save(qe);


org.springframework.dao.DataIntegrityViolationException: could not insert

when i try to insert a record in database like this:
insert into query_info (title) values ('test');

ok, when I load it , it said:
Can not set int field com.osssoft.query.entity.QueryEntry.parentId to null value

i think I have already set it's nullable is true,
any body can help me ?

this is my code , this question burder me server days
Code:
package com.osssoft.query.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
* 查询入口,记录查询语句与与层次树状关系
*
* @author lvjian
*
*/
@Entity
@Table(name = "query_entry")
public class QueryEntry implements Serializable {

   private static final long serialVersionUID = -7413534140036087322L;

   @Id
   @GeneratedValue
   private int id;


   @Column(name = "title", length = 100)
   private String title;


   @Column(name = "parent_id")
   private int parentId;


   @ManyToOne
   @JoinColumn(name = "parent_id", insertable = false, updatable = false, nullable = true)
   private QueryEntry parent;


   @OneToMany(mappedBy = "parent")
   private Set<QueryEntry> children = new HashSet<QueryEntry>();

   @Column(name = "prepare_sql", length = 2000)
   private String prepareSql;

   @Column(name = "query_sql", length = 2000)
   private String querySql;

   @Column(name = "clean_sql", length = 1000)
   private String cleanSql;

   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   public String getTitle() {
      return title;
   }

   public void setTitle(String title) {
      this.title = title;
   }

   public int getParentId() {
      return parentId;
   }

   public void setParentId(int parentId) {
      this.parentId = parentId;
   }

   public QueryEntry getParent() {
      return parent;
   }

   public void setParent(QueryEntry parent) {
      this.parent = parent;
   }

   public Set<QueryEntry> getChildren() {
      return children;
   }

   public void setChildren(Set<QueryEntry> children) {
      this.children = children;
   }

   public String getPrepareSql() {
      return prepareSql;
   }

   public void setPrepareSql(String prepareSql) {
      this.prepareSql = prepareSql;
   }

   public String getSql() {
      return querySql;
   }

   public void setSql(String querySql) {
      this.querySql = querySql;
   }

   public String getCleanSql() {
      return cleanSql;
   }

   public void setCleanSql(String cleanSql) {
      this.cleanSql = cleanSql;
   }

}

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 1:49 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
primitives cannot be null, consider using Integer instead.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 11:58 pm 
Newbie

Joined: Tue Jun 26, 2007 10:04 pm
Posts: 4
thank for your help ,
i resolve this problem


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 9:53 am 
Beginner
Beginner

Joined: Thu Nov 02, 2006 9:38 am
Posts: 32
Location: Belgium
furk wrote:
thank for your help ,
i resolve this problem


In that case, rate his post so he gets credit :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.