Total members 11890 |It is currently Sat Apr 20, 2024 8:35 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





To get all entity records for a you can follow the example below , it can give you a simple guide throw your investigation .



JPA service class :
Code:

package com
.codemiles.jpa;

import java.util.List;

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

/**
 * @author codemiles.
 */
public abstract class JPAService {
    private 
EntityManager entityManager;

    public List<
PersonfindAllPersons(String Id) {
    
EntityManagerFactory factory Persistence
            
.createEntityManagerFactory("persistenceUnitName");
    
entityManager factory.createEntityManager();
    
entityManager.getTransaction().begin();
    List<
PersonlistPersons entityManager.createQuery(
            
"SELECT p FROM Person p").getResultList();
    
entityManager.getTransaction().commit();
    
entityManager.close();
    
factory.close();
    if (
listPersons == null) {
        
System.out.println("No persons found . ");
    } else {
        for (
Person person listPersons) {
        
System.out.print("Person name= " person.getName()
                + 
", gender" person.getGender() + ", birthday="
                
person.getBirthday());
        }
    }

    return 
listPersons;
    }

}

 



entity class:
Code:

package com
.codemiles.jpa;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@
Entity
@Table(name="PERSON")
public class 
Person implements java.io.Serializable{
    
/**
     * 
     */
    
private static final long serialVersionUID 1L;
    @
Id
    
private String Id;
    private 
String name;
    private 
Date birthday;
    private 
String gender;
    
    @
OneToOne(mappedBy="person"
    private 
Bed bed;
    
    public 
String getId() {
        return 
Id;
    }
    public 
void setId(String id) {
        
Id id;
    }
    @
Column(name="NAME")
    public 
String getName() {
        return 
name;
    }
    public 
void setName(String name) {
        
this.name name;
    }
    @
Column(name="BIRTHDAT")
    public 
Date getBirthday() {
        return 
birthday;
    }
    public 
void setBirthday(Date birthday) {
        
this.birthday birthday;
    }
    @
Column(name="GENDER")
    public 
String getGender() {
        return 
gender;
    }
    public 
void setGender(String gender) {
        
this.gender gender;
    }
    public 
void setBed(Bed bed) {
    
this.bed bed;
    }
    public 
Bed getBed() {
    return 
bed;
    }
 
    
}
 




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Get all objects for an entity
 Using Web Objects in XML (WOX) to serialize Java objects XML     -  
 Smart Objects in photoshop     -  
 Eligible objects for garbage collectors     -  
 what is object's lock and which objects have locks ?     -  
 queue of objects keep track of the front and rear     -  
 invalid argument on IE with script to center objects     -  
 cmp entity beans     -  
 Find entity by id     -  
 JPA entity class example     -  
 @EntityListeners in your entity class     -  



Topic Tags

Java JPA






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com