title: How to insert data into the database using spring + hibernate?
body: <p>see i m havving user.java for the user info.</p>
  
  <pre><code>@Entity(name = "user")
  @Table(name = "user")
  public class User {
  
      @Id
      @Column(name = "id")
      private String id;  
      @Column(name = "password")
      private String password;
  //getter and setter for this..
  }
  </code></pre>
  
  <p>this is my userdao</p>
  
  <pre><code>public class UserDao {
      public interface UserDAO {
          public String insert(User user);
  
      }
  }
  </code></pre>
  
  <p>and this is the impl class for inserting into database
  see this was my code.please check it and tell me what i m doing wrong </p>
  
  <pre><code>@Repository
  @Transactional
  public class UserImpl implements UserDAO {
  
      private DataSource dataSource;
  
      @Autowired
      SessionFactory sessionFactory;
      @Resource(name = "sessionFactory")
      public void setDataSource(DataSource dataSource) {
          this.dataSource = dataSource;
      }
  
      @Override
      public String insert(User use) {
  
          Session session = this.sessionFactory.openSession();
          try{
  
              Session sess = this.sessionFactory.getCurrentSession();              
              session.save(reg);
  
  
                          return (String)user.getUserName(); 
                          }catch(Exception e){
                              System.out.println("in catch"+e.getMessage());
                              e.printStackTrace();
  
      }
  
      }
  }
  
  
  
  
  } 
  </code></pre>
  
  <p>and in my controller after successful registration i m inserting data to the database by this  </p>
  
  <pre><code> userDao.insert(user);
  </code></pre>
  
  <p>but i m not getting output means not any data is inserting into the database.why this..? this is my mvc configuration </p>
  
  <pre><code>&lt;context:component-scan base-package="com.user.xyz" /&gt;
      &lt;mvc:annotation-driven /&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/images/, /resources/css/" /&gt;
      &lt;bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/view/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
  
      &lt;/bean&gt;
  </code></pre>