Home Hibernate Hibernate4 net.roseindia.dao
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

net.roseindia.dao

Advertisement
This package is the part of Spring and Hibernate JPA integration application which contains DAO service interface and it's implementation class.

net.roseindia.dao

This package is the part of  Spring and Hibernate JPA  integration application which contains DAO service interface and it's implementation class.

For returning to main example(Spring Jpa Hibernate). Click here.

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 javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import net.roseindia.model.Article;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

@Repository("articleDao")
public class ArticleDaoImpl implements ArticleDao {

private EntityManager em;

@PersistenceContext
public void setEntityManager(EntityManager em) {
this.em = em;
}

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

// To get list of all articles
@SuppressWarnings("unchecked")
public List<Article> listArticles() {
Session session = (Session) em.getDelegate();
return (List<Article>) session.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: May 7, 2012

Related Tutorials

Ask Questions?    Discuss: net.roseindia.dao  

Post your Comment


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