Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Spring Spring3.2 net.roseindia.dao

Related Tutorials


 
 

Share on Google+Share on Google+

net.roseindia.dao

Advertisement
This section contains the DAO interface and its implementation class.

net.roseindia.dao

This section contains the DAO interface and its implementation class.

ArticleDao.java

package net.roseindia.dao;

import java.util.List;

import net.roseindia.model.Article;

public interface ArticleDao {
	// To Save the article detail
	public void saveArticle(Article Article);
	
	// To get list of all articles
	public List<Article> listArticles();
}

ArticleDaoImpl.java

package net.roseindia.dao;

import java.util.Date;
import java.util.List;

import net.roseindia.model.Article;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("articleDao")
public class ArticleDaoImpl implements ArticleDao {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	// To Save the article detail
	public void saveArticle(Article article) {
	article.setAddedDate(new Date());
	sessionFactory.getCurrentSession().saveOrUpdate(article);
	}
	
	// To get list of all articles
	@SuppressWarnings("unchecked")
	public List<Article> listArticles() {
	return (List<Article>) sessionFactory.getCurrentSession()
	.createCriteria(Article.class).list();
	}
}
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 28, 2013

Related Tutorials

Discuss: net.roseindia.dao  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com