1. #1
    Sencha User
    Join Date
    Apr 2011
    Location
    Surat, Gujarat, India
    Posts
    126
    Vote Rating
    0
    rushi2440 is on a distinguished road

      0  

    Thumbs up Unanswered: How to assign JSON Object to Hibernate Pojo + ext js 4 + Java + spring

    Unanswered: How to assign JSON Object to Hibernate Pojo + ext js 4 + Java + spring


    HI.. sencha forum member I need one support from you.

    I am getting my JSON value on server side as
    Code:
    "Id": null,
        "Name": "New task",
        "StartDate": "2010-02-03T05:30:00",
        "EndDate": "2010-02-04T05:30:00",
        "Duration": 1,
        "DurationUnit": "d",
        "PercentDone": 0,
        "ManuallyScheduled": false,
        "Priority": 1,
        "parentId": 8,
        "index": 0,
        "depth": 3,
        "checked": null
    my Task. POJO class is
    Code:
    @JsonAutoDetect
    @Entity
    @Table(name = "TASK")
    public class Task {
        
        private int Id;
        private Date StartDate;
        private Date EndDate;
        private int PercentDone;
        private String Name;
        private int Priority;
        private double Duration;
        private String DurationUnit;
        private int index;
        private int depth;
        private int parentId;
        
        /**
         * @return the id
         */
        @Id
        @GeneratedValue
        @Column(name = "TASK_Id")
        @JsonProperty("Id")
        public int getId() {
            return Id;
        }
        /**
         * @param id the id to set
         */
        public void setId(int Id) {
            this.Id = Id;
        }
        
        /**
         * @return the startDate
         */
        @Temporal(TemporalType.DATE)
        @Column(name = "TASK_Start_Date")
        @JsonProperty("StartDate")
        public Date getStartDate() {
            return StartDate;
        }
        /**
         * @param startDate the startDate to set
         */
        public void setStartDate(Date StartDate) {
            this.StartDate = StartDate;
        }
        
        /**
         * @return the endDate
         */    
        @Temporal(TemporalType.DATE)
        @Column(name = "TASK_End_Date")
        @JsonProperty("EndDate")
        public Date getEndDate() {
            return EndDate;
        }
        /**
         * @param endDate the endDate to set
         */
        public void setEndDate(Date EndDate) {
            this.EndDate = EndDate;
        }
        
        /**
         * @return the percentDone
         */    
        @Column(name = "TASK_Percent_Done")
        @JsonProperty("PercentDone")
        public int getPercentDone() {
            return PercentDone;
        }
        /**
         * @param percentDone the percentDone to set
         */
        public void setPercentDone(int PercentDone) {
            this.PercentDone = PercentDone;
        }
        
        /**
         * @return the name
         */
        @Column(name = "TASK_Name")
        @JsonProperty("Name")
        public String getName() {
            return Name;
        }
        /**
         * @param name the name to set
         */
        public void setName(String Name) {
            this.Name = Name;
        }
        
        /**
         * @return the priority
         */
        @Column(name = "TASK_Priority")
        @JsonProperty("Priority")
        public int getPriority() {
            return Priority;
        }
        /**
         * @param priority the priority to set
         */
        public void setPriority(int Priority) {
            this.Priority = Priority;
        }
        
        /**
         * @return the duration
         */
        @Column(name = "TASK_Duration")
        @JsonProperty("Duration")
        public double getDuration() {
            return Duration;
        }
        /**
         * @param duration the duration to set
         */
        public void setDuration(double Duration) {
            this.Duration = Duration;
        }
        
        /**
         * @return the durationUnit
         */
        @Column(name = "TASK_DurationUnit")
        @JsonProperty("DurationUnit")
        public String getDurationUnit() {
            return DurationUnit;
        }
        /**
         * @param durationUnit the durationUnit to set
         */
        public void setDurationUnit(String DurationUnit) {
            this.DurationUnit = DurationUnit;
        }
        
        /**
         * @return the index
         */
        @Column(name = "TASK_Index")
        @JsonProperty("index")
        public int getIndex() {
            return index;
        }
        /**
         * @param index the index to set
         */
        public void setIndex(int index) {
            this.index = index;
        }
        
        /**
         * @return the depth
         */
        @Column(name = "TASK_Depth")
        @JsonProperty("depth")
        public int getDepth() {
            return depth;
        }
        /**
         * @param depth the depth to set
         */
        public void setDepth(int depth) {
            this.depth = depth;
        }
        
        /**
         * @return the parentId
         */
        @Column(name = "TASK_ParentId")
        @JsonProperty("parentId")
        public int getParentId() {
            return parentId;
        }
        /**
         * @param parentId the parentId to set
         */
        public void setParentId(int parentId) {
            this.parentId = parentId;
        }    
    }
    I am assigning the received JSON object value to my POJO, but something is wrong that I am not able to do so.

    To assign JSON Object to POJO, I am using
    Code:
    JSONObject jsonObject = JSONObject.fromObject(data);
    System.out.println("JSON OBJECT ::"+jsonObject+"::"+Task.class);
    Task newTask = (Task) JSONObject.toBean(jsonObject, Task.class);
    I am able to print my Json Object correctly, but don't know why it is not getting assigned to my Task model.

    Help me to find the mistake I am to do my work, so my Task get persisted to database

    Yogendra Singh
    Sr. Programmer
    Kintudesigns.com

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,795
    Answers
    3466
    Vote Rating
    834
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    So what in Ext JS 4 is wrong?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Location
    Surat, Gujarat, India
    Posts
    126
    Vote Rating
    0
    rushi2440 is on a distinguished road

      0  

    Thumbs up Not able to insert record to database using Hibernate + JPA

    Not able to insert record to database using Hibernate + JPA


    hi...
    mitchellsimoens

    One problem i am facing is that i am not able to insert my data to database using Hibernate + JPA.
    I am sending the data to server side using JSON and then this object interact with database and insert the json object to the database.

    I am sending the json data as
    Code:
    [{
        "Id": null,
        "Name": "New task",
        "StartDate": "2010-02-13T05:30:00",
        "EndDate": "2010-02-13T05:30:00",
        "Duration": 0,
        "DurationUnit": "d",
        "PercentDone": 0,
        "ManuallyScheduled": false,
        "Priority": 1,
        "parentId": 22,
        "index": 2,
        "depth": 2,
        "checked": null
    }]
    my Hibernate POJO is
    Code:
    @JsonAutoDetect
    @Entity
    @Table(name = "TASK")
    public class Task {
        
        private int id;
        private Date startDate;
        private Date endDate;
        private int percentDone;
        private String name;
        private int priority;
        private double duration;
        private String durationUnit;
        private int index;
        private int depth;
        private int parentId;
        
        /**
         * @return the id
         */
        @Id
        @GeneratedValue
        @Column(name = "TASK_Id")
        public int getId() {
            return id;
        }
        /**
         * @param id the id to set
         */
        public void setId(int Id) {
            this.id = Id;
        }
        
        /**
         * @return the startDate
         */
        @Temporal(TemporalType.DATE)
        @Column(name = "TASK_Start_Date")
        public Date getStartDate() {
            return startDate;
        }
        /**
         * @param startDate the startDate to set
         */
        public void setStartDate(Date StartDate) {
            this.startDate = StartDate;
        }
        
        /**
         * @return the endDate
         */    
        @Temporal(TemporalType.DATE)
        @Column(name = "TASK_End_Date")
        public Date getEndDate() {
            return endDate;
        }
        /**
         * @param endDate the endDate to set
         */
        public void setEndDate(Date EndDate) {
            this.endDate = EndDate;
        }
        
        /**
         * @return the percentDone
         */    
        @Column(name = "TASK_Percent_Done")
        public int getPercentDone() {
            return percentDone;
        }
        /**
         * @param percentDone the percentDone to set
         */
        public void setPercentDone(int PercentDone) {
            this.percentDone = PercentDone;
        }
        
        /**
         * @return the name
         */
        @Column(name = "TASK_Name")
        public String getName() {
            return name;
        }
        /**
         * @param name the name to set
         */
        public void setName(String Name) {
            this.name = Name;
        }
        
        /**
         * @return the priority
         */
        @Column(name = "TASK_Priority")
        public int getPriority() {
            return priority;
        }
        /**
         * @param priority the priority to set
         */
        public void setPriority(int Priority) {
            this.priority = Priority;
        }
        
        /**
         * @return the duration
         */
        @Column(name = "TASK_Duration")
        public double getDuration() {
            return duration;
        }
        /**
         * @param duration the duration to set
         */
        public void setDuration(double Duration) {
            this.duration = Duration;
        }
        
        /**
         * @return the durationUnit
         */
        @Column(name = "TASK_DurationUnit")
        public String getDurationUnit() {
            return durationUnit;
        }
        /**
         * @param durationUnit the durationUnit to set
         */
        public void setDurationUnit(String DurationUnit) {
            this.durationUnit = DurationUnit;
        }
        
        /**
         * @return the index
         */
        @Column(name = "TASK_Index")
        public int getIndex() {
            return index;
        }
        /**
         * @param index the index to set
         */
        public void setIndex(int index) {
            this.index = index;
        }
        
        /**
         * @return the depth
         */
        @Column(name = "TASK_Depth")
        public int getDepth() {
            return depth;
        }
        /**
         * @param depth the depth to set
         */
        public void setDepth(int depth) {
            this.depth = depth;
        }
        
        /**
         * @return the parentId
         */
        @Column(name = "TASK_ParentId")
        public int getParentId() {
            return parentId;
        }
        /**
         * @param parentId the parentId to set
         */
        public void setParentId(int parentId) {
            this.parentId = parentId;
        }    
    }
    when i am passing the above JSON data nothing get inserted to my database.
    my hibernate query fires like
    Code:
    Hibernate: insert into TASK(TASK_Depth, TASK_Duration, TASK_DurationUnit, TASK_End_Date, TASK_Index, TASK_Name, TASK_ParentId, TASK_Percent_Done, TASK_Priority, TASK_Start_Date)
        values( ? , ?, ?, ?, ?, ?, ?, ?, ?, ?)
    nothing get inserted to my database. As my class id is autoincreemented the record gets created with empty name, startDate, endDate, parentId


    So my question is that what the things i am doing wrong. Is there any problem with my hibernate Pojo mappings . If yes then any one having solution to this problem may reply to my thread.

    Yogendra Singh
    Sr. Programmer
    Kintudesigns.com

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi