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.

Ads

Tutorials   
How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate 4.3.4 Released: Hibernate 4.3.4.Final Maven dependency Hibernate 4.3 Hello World: Example How to create SessionFactory in Hibernate 4.3.1? Hibernate 4 Hello World: Example of Hello World program Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4 Hibernate 4.3 and JPA 2.1 Example What is Hibernate in Java? Hibernate Overview and Architecture What is JPA 2.1? Hibernate 4.3.0.Final Maven dependency Hibernate 4.3 ORM Features Hibernate 4.3 Tutorial Hibernate Criteria average example Hibernate Criteria load all objects from table Hibernate Criteria Hibernate beginner tutorial Hibernate Session.delete() Example Hibernate save or update method example Hibernate Load Example Hibernate save Example - Rose India Hibernate 4 tutorials Hibernate Example Step by Step in Eclipse Hibernate Configuration files Setup Hibernate Environment Hibernate Architecture Hibernate Overview Hibernate 4.2 Tutorial Hibernate 4 Annotations Tutorial Hibernate 4 AnnotationSessionFactoryBean hibernate versions hibernate jndi hibernate tomcat hibernate metamodel generator hibernate entity Seam Hibernate C3P0 Hibernate hibernate shard hibernate means temporal hibernate jsf hibernate spring j2ee hibernate spring hibernate encrypted password alias_to_entity_map hibernate temporal jsf spring hibernate hibernate by example hibernate repository hibernate sample code
Ads

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();
}
}

 

Advertisements

Share on Google+Share on Google+

net.roseindia.dao

Posted on: May 7, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: net.roseindia.dao  

Post your Comment


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

Ads

 

Ads