Total members 10262 | Gratitudes |It is currently Wed May 23, 2012 9:17 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: beginning and finishing the JPA transaction
PostPosted: Tue Apr 20, 2010 4:31 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

He is an small example to show you how to control the transaction (like starting and committing actions ) .


Code:

package com
.codemiles.jpa;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public abstract class 
JPAService {
    private   
EntityManager  entityManager;
    
/**
     * @param args
     */
    
public void insertTopic(Topic topic){
     
EntityManagerFactory factory Persistence
         
.createEntityManagerFactory("persistenceUnitName");
         
entityManager factory.createEntityManager();
         
entityManager.getTransaction().begin();
         
entityManager.persist(topic);
         
entityManager.getTransaction().commit();
         
entityManager.close();
         
factory.close();
         
    }
 

}

 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Beginning Programming with Java For Dummies, 2nd Edition
 (Wrox) Beginning Microsoft Visual CSharp 2008
 Beginning CSharp 2008
 (Apress) Beginning Csharp Objects - From Concepts to Cod
 (Apress) Beginning C Sharp 2008 Databases From Novice to Pro
 Beginning C# 2008: From Novice to Professional, Second Editi
 Beginning Php5 Apache And Mysql Web Development
 Beginning AJAX with PHP5

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team