Announcement Announcement Module
No announcement yet.
How to enter data in two tables at one time in spring mvc hibernate Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to enter data in two tables at one time in spring mvc hibernate

    Article class:

    @Table(name = "imei")
    public class Article {
    // @GeneratedValue
    @Column(name = "imei1",nullable = false)
    private Long imeiNo;
    @Column(name = "date_added")
    @Temporal(javax.persistence.TemporalType.TIMESTAMP )
    private Date addedDate;
    public Article() {
    public Long getImeiNo() {
    return imeiNo;
    public void setImeiNo(Long imeiNo) {
    this.imeiNo = imeiNo;
    public Date getAddedDate() {
    return addedDate;

    public void setAddedDate(Date addedDate) {
    this.addedDate = addedDate;
    ArticleDaoImpl Class:

    public class ArticleDaoImpl implements ArticleDao {

    private SessionFactory sessionFactory;

    // To Save the article detail
    public void saveArticle(Article article) {
    article.setAddedDate(new Date());

    sessionFactory.getCurrentSession().saveOrUpdate(ar ticle);

    // To get list of all articles
    public List<Article> listArticles() {
    return (List<Article>) sessionFactory.getCurrentSession().createCriteria( Article.class).list();

    public class ArticleController {

    private ArticleService articleService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ModelAndView saveArticle(@ModelAttribute(" article") Article article,
    BindingResult result) {
    articleService.addArticle( article);
    return new ModelAndView("redirect:/articles.html");

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView listArticles() {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("articles", articleService.listArticles());

    return new ModelAndView("articlesList", model);

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public ModelAndView addArticle(@ModelAttribute("article") Article article,
    BindingResult result) {
    return new ModelAndView("addArticle");

    ArticleServiceImpl class:

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public class ArticleServiceImpl implements ArticleService {

    private ArticleDao articleDao;

    public ArticleServiceImpl() {

    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public void addArticle(Article article) {

    public List<Article> listArticles() {
    return articleDao.listArticles();

    can you tell me that how to enter value in two tables at one time?? because i have to enter imei number in one table and imei and date and time in second table. i have perform working of second table but i didnt know how to enter values at one time in two tables. Please help me