2012-01-27 23 views
2

私はプロジェクトのクラスPOJOタスククラスPOJOが休止一対多リレーションシップ・データ挿入エラー

@Entity 
@Table(name = "task", catalog = "primavera") 
public class Task implements java.io.Serializable { 

    private Integer taskId; 
    private Integer depth; 
    private Double duration; 
    private String durationUnit; 
    private Date endDate; 
    private Integer parentId; 
    private Integer percentDone; 
    private Integer priority; 
    private Date startDate; 
    private Integer taskIndex; 
    private String taskName; 

    public Task() { 
    } 

    public Task(Integer depth, Double duration, String durationUnit, 
      Date endDate, Integer parentId, Integer percentDone, 
      Integer priority, Date startDate, Integer taskIndex, 
      String taskName) { 
     this.depth = depth; 
     this.duration = duration; 
     this.durationUnit = durationUnit; 
     this.endDate = endDate; 
     this.parentId = parentId; 
     this.percentDone = percentDone; 
     this.priority = priority; 
     this.startDate = startDate; 
     this.taskIndex = taskIndex; 
     this.taskName = taskName; 
    } 

    public Task(String string, Object object) { 
     // TODO Auto-generated constructor stub 
    } 

    @Id 
    @GeneratedValue 
    @Column(name = "task_id") 
    public Integer getTaskId() { 
     return this.taskId; 
    } 

    public void setTaskId(Integer taskId) { 
     this.taskId = taskId; 
    } 

    @Column(name = "depth") 
    public Integer getDepth() { 
     return this.depth; 
    } 

    public void setDepth(Integer depth) { 
     this.depth = depth; 
    } 

    @Column(name = "duration", precision = 22, scale = 0) 
    public Double getDuration() { 
     return this.duration; 
    } 

    public void setDuration(Double duration) { 
     this.duration = duration; 
    } 

    @Column(name = "durationUnit") 
    public String getDurationUnit() { 
     return this.durationUnit; 
    } 

    public void setDurationUnit(String durationUnit) { 
     this.durationUnit = durationUnit; 
    } 

    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name = "endDate", length = 19) 
    public Date getEndDate() { 
     return this.endDate; 
    } 

    public void setEndDate(Date endDate) { 
     this.endDate = endDate; 
    } 

    @Column(name = "parentId") 
    public Integer getParentId() { 
     return this.parentId; 
    } 

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

    @Column(name = "percentDone") 
    public Integer getPercentDone() { 
     return this.percentDone; 
    } 

    public void setPercentDone(Integer percentDone) { 
     this.percentDone = percentDone; 
    } 

    @Column(name = "priority") 
    public Integer getPriority() { 
     return this.priority; 
    } 

    public void setPriority(Integer priority) { 
     this.priority = priority; 
    } 

    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name = "startDate", length = 19) 
    public Date getStartDate() { 
     return this.startDate; 
    } 

    public void setStartDate(Date startDate) { 
     this.startDate = startDate; 
    } 

    @Column(name = "taskIndex") 
    public Integer getTaskIndex() { 
     return this.taskIndex; 
    } 

    public void setTaskIndex(Integer taskIndex) { 
     this.taskIndex = taskIndex; 
    } 

    @Column(name = "taskName") 
    public String getTaskName() { 
     return this.taskName; 
    } 

    public void setTaskName(String taskName) { 
     this.taskName = taskName; 
    } 

} 

私は以下のことで、私のPOJOにデータを割り当てるしようとしていると

@Entity 
@Table(name = "project", catalog = "primavera") 
public class Project implements java.io.Serializable { 

    private Integer projectId; 
    private Date endDate; 
    private String projectDesc; 
    private String projectName; 
    private String projectTitle; 
    private Date startDate; 
    private Set<Task> tasks = new HashSet<Task>(0); 

    public Project() { 
    } 

    public Project(Date endDate, String projectDesc, String projectName, 
      String projectTitle, Date startDate, Set<Task> tasks) { 
     this.endDate = endDate; 
     this.projectDesc = projectDesc; 
     this.projectName = projectName; 
     this.projectTitle = projectTitle; 
     this.startDate = startDate; 
     this.tasks = tasks; 
    } 

    @Id 
    @GeneratedValue 
    @Column(name = "project_id") 
    public Integer getProjectId() { 
     return this.projectId; 
    } 

    public void setProjectId(Integer projectId) { 
     this.projectId = projectId; 
    } 

    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name = "endDate", length = 19) 
    public Date getEndDate() { 
     return this.endDate; 
    } 

    public void setEndDate(Date endDate) { 
     this.endDate = endDate; 
    } 

    @Column(name = "projectDesc") 
    public String getProjectDesc() { 
     return this.projectDesc; 
    } 

    public void setProjectDesc(String projectDesc) { 
     this.projectDesc = projectDesc; 
    } 

    @Column(name = "projectName") 
    public String getProjectName() { 
     return this.projectName; 
    } 

    public void setProjectName(String projectName) { 
     this.projectName = projectName; 
    } 

    @Column(name = "projectTitle") 
    public String getProjectTitle() { 
     return this.projectTitle; 
    } 

    public void setProjectTitle(String projectTitle) { 
     this.projectTitle = projectTitle; 
    } 

    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name = "startDate", length = 19) 
    public Date getStartDate() { 
     return this.startDate; 
    } 

    public void setStartDate(Date startDate) { 
     this.startDate = startDate; 
    } 

    @OneToMany(cascade = CascadeType.ALL) 
    @JoinTable(name = "project_task", joinColumns = { @JoinColumn(name = "project_id") }, inverseJoinColumns = { @JoinColumn(name = "task_id") }) 
    public Set<Task> getTasks() { 
     return this.tasks; 
    } 

    public void setTasks(Set<Task> tasks) { 
     this.tasks = tasks; 
    } 

} 

た関係を持っていますコードJSON

Set<Task> taskdata = new HashSet<Task>(); 
     taskdata.add(new Task(null,null,null,endD1,null,null,null,startD1,null,null)); 

jsonObject.put("projectTitle", jsonObject.getString("title")); 
     jsonObject.put("projectName", jsonObject.getString("name")); 
     jsonObject.put("projectDesc", jsonObject.getString("description").replace("\u200b", "")); 
     jsonObject.put("startDate", startD); 
     jsonObject.put("endDate", endD); 
     jsonObject.put("tasks", taskdata); 

Project project = (Project) JSONObject.toBean(jsonObject, Project.class); 

を使用していますが、私は目を渡していていてもが仕事であると思いませんでしたeはtaskdataとして設定し、また、私は

35802 [HTTP-8085から4] ERROR org.hibernate.property.BasicPropertyAccessorのようなエラーを取得しています - クラスではIllegalArgumentException:com.kintu.projectmgt.model.Task、getterメソッドプロパティの:taskId

私のデータがデータベースに完全に挿入されないようにする問題を見つけるのを手伝ってください。デフォルトモードでは通常@GeneratedValue

@GeneratedValue(strategy=GenerationType.AUTO) 

または

@GeneratedValue(strategy=GenerationType.TABLE) 

のような戦略を追加すること

+0

この回答を確認すると、休止状態のバグかもしれません:http://stackoverflow.com/questions/3631349/how-do-i-cure-the-cause-of-hibernate-exception-illegalargumentexception-occurre 'hibernate.cache.use_structured_entries = true'を設定してみてください – fasseg

+0

解決策はまだ同じエラーではありません。しかしもう一つこれは、JSONを使用して、タスククラスとの関係を持つプロジェクトクラスにデータを割り当てる正しい方法です。またはデータを完全に挿入するために他の手法を使用しなければならないのですか? –

+0

これは問題ありませんが、簡単にこれをデバッグし、 'JSONObject.toBean()'によって作成された 'Project'インスタンスに必要なフィールドがすべて設定されているかどうか確認できます。 – fasseg

答えて

0

てみてくださいはロングに書き込むために使用されます。
また、OneToManyは、もう一方のモデルクラスでManyToOneと予想されることがあります。

+0

解決法ではありませんそれでもなおエラーが出ます。実際には、私はJsonObjectからProjectに値を割り当てる方法が正しいとは思わない。このための解決策はありますか? –

関連する問題