title: How to set type Date in DaoImpl class in java
body: <p>posting type date to postgresql using spring mvc 
  I have one to many relation in DealPosted class with the other table.dealcatid is the foreign key in this class. how can i get that dealcatid?</p>
  
  <p>this is my bean class</p>
  
  <pre><code>package com.saveDollar.model;
  
  
  
  import java.io.Serializable;
  import java.sql.Time;
  import java.sql.Timestamp;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.persistence.JoinColumn;
  
  @Entity
  @Table(name="tbldeals_posted")
  
  public class DealPosted implements Serializable
  {
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
      int DealID;
      String PostedBy;
      String DeaTitle;
      String DealDesc;
      int Days;
      Time FromTime;
      Time ToTime;
      SimpleDateFormat formatter=new SimpleDateFormat("dd-mm-yy");
      Date StartDate;
      Date EndDate;
      boolean is_deleted;
  
      private Set&lt;DealCategory&gt; dealCategory = new HashSet&lt;DealCategory&gt;(0);
      private Set&lt;City&gt; city=new HashSet&lt;City&gt;(0);
  
      public DealPosted()
       {
  
       }
  
       public DealPosted(String PostedBy,String DeaTitle,String DealDesc,Set&lt;City&gt; city,
               Date StartDate,Date EndDate,int Days,Time FromTime,Time ToTime,boolean is_deleted,
               Set&lt;DealCategory&gt;  dealCategory)
       {
           this.dealCategory=dealCategory;
           this.PostedBy=PostedBy;
           this.DeaTitle=DeaTitle;
           this.DealDesc=DealDesc;
           this.StartDate=StartDate;
           this.EndDate=EndDate;
           this.Days=Days;
           this.FromTime=FromTime;
           this.ToTime=ToTime;
           this.city=city;
           this.is_deleted=is_deleted;
      }
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name="dealid")
      public int getDealID() 
      {
          return DealID;
      }
  
      public void setDealID(int dealID) 
      {
          DealID = dealID;
      }
      @Column(name="postedby")
      public String getPostedBy() 
      {
          return PostedBy;
      }
  
      public void setPostedBy(String postedBy)
      {
          PostedBy = postedBy;
      }
  
      @Column(name="deatitle")
      public String getDeaTitle() {
          return DeaTitle;
      }
  
  
      @Column(name="is_deleted")
      public boolean getIs_deleted(boolean is_deleted)
      {
          return is_deleted;
      }
  
      public void setIs_deleted(boolean is_deleted) 
      {
          this.is_deleted = is_deleted;
      }
  
      public void setDeaTitle(String deaTitle) 
      {
          DeaTitle = deaTitle;
      }
      @Column(name="dealdesc")
      public String getDealDesc() {
          return DealDesc;
      }
  
      public void setDealDesc(String dealDesc) 
      {
          DealDesc = dealDesc;
      }
      @Column(name="startdate")
      public Date getStartDate() 
      {
          return StartDate;
      }
      public void setStartDate(Date startDate)
      {
          StartDate = startDate;
      }
      @Column(name="enddate")
      public Date getEndDate() 
      {
          return EndDate;
      }
  
      public void setEndDate(Date endDate) 
      {
          EndDate = endDate;
      }
      @Column(name="days")
      public int getDays() {
          return Days;
      }
  
      public void setDays(int days) {
          Days = days;
      }
      @Column(name="fromtime")
      public Time getFromTime() {
          return FromTime;
      }
  
      public void setFromTime(Time fromTime) {
          FromTime = fromTime;
      }
      @Column(name="totime")
      public Time getToTime() {
          return ToTime;
      }
  
      public void setToTime(Time toTime) 
      {
          ToTime = toTime;
      }
  
      /*@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
      @JoinTable(name="city",joinColumns={@JoinColumn(name="cityid")})*/
  
      @OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
      @JoinColumn(name="cityid")
      public Set&lt;City&gt; getCity() 
      {
          return city;
      }
      public void setCity(Set&lt;City&gt; city) 
      {
          this.city = city;
      }
      @OneToMany(fetch=FetchType.EAGER,mappedBy = "dealcatid",cascade=CascadeType.ALL)
       public Set&lt;DealCategory&gt; getDealCategory() 
       {
          return dealCategory;
       }
      public void setDealCategory(Set&lt;DealCategory&gt; dealCategory)
      {
          this.dealCategory=dealCategory;
      }
  }
  
  
  this is my DealDaoImpl class
  
       public class DealDaoImpl implements DealDao   
          {
  
  
              private SessionFactory sessionFactory;
              private Session session=null;
  
              @Autowired
              public void setSessionFactory(SessionFactory sessionFactory) 
              {
                  this.sessionFactory = sessionFactory;
              }
              @SuppressWarnings("unchecked")
              @Override
              public List&lt;DealPosted&gt; getAllDeals() 
              {
                  session =sessionFactory.getCurrentSession();
                   List&lt;DealPosted&gt; deals =  (List&lt;DealPosted&gt;) session.
                           createSQLQuery("select * from tbldeals_posted d")
                           .addEntity("d", DealPosted.class)
                           .list();
                   return deals;
              }
              @Override
              public int addDeal(DealPosted dealPosted) 
              {
                  final Calendar calendar = new GregorianCalendar();
                  dealPosted.setStartDate(calendar.getTime());
  
                  dealPosted.setDealID(3);
                  dealPosted.setPostedBy("Rama");
                  dealPosted.setDeaTitle("pizza");
  
                  dealPosted.setEndDate(calendar.getTime());
                  dealPosted.setDealDesc("abc");
                  dealPosted.setDays(4);
  
                  session=sessionFactory.getCurrentSession();
                  session.save(dealPosted);
                  return dealPosted.getDealID();
              }
  
               Hibernate: insert into tbldeals_posted (days, postedby, deatitle, dealdesc, startdate, enddate, fromtime, totime) values (?, ?, ?, ?, ?, ?, ?, ?)
              2014-03-14 18:33:32 WARN  JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 23502
              2014-03-14 18:33:32 ERROR JDBCExceptionReporter:78 - ERROR: null value in column "dealcatid" violates not-null constraint
                Detail: Failing row contains (11, null, Rama                                              , pizza                                             , abc, null, null, null, null, 4, null, null, null).
  </code></pre>
  
  <p>I am unable to reolve the issue.
  give any suggestions on this issue
  thanks</p>