Switch to full style
Java persistent API
Post a reply

JPA entity class example

Sat Mar 13, 2010 10:15 pm

This is a simple JPA entity class example for "topic" table using Java annotations .
Code:

import javax
.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;


@
Entity
@Table(name="TOPIC")
public class 
topic {

    private 
long Id;
    private 
String title;
    private 
Date creationDate;
    private 
Date modifedDate;
    private 
String content;
    
    @
Id
    
@GeneratedValue
    
public long getId() {
        return 
Id;
    }
    public 
void setId(long id) {
        
Id id;
    }
    
    @
Column(name="TITLE")
    public 
String getTitle() {
        return 
title;
    }
    public 
void setTitle(String title) {
        
this.title title;
    }
    
    @
Column(name="CREATION_DATE")
    public 
Date getCreationDate() {
        return 
creationDate;
    }
    public 
void setCreationDate(Date creationDate) {
        
this.creationDate creationDate;
    }
    
    @
Column(name="MODIFED_DATE")
    public 
Date getModifedDate() {
        return 
modifedDate;
    }
    public 
void setModifedDate(Date modifedDate) {
        
this.modifedDate modifedDate;
    }
    
    @
Column(name="CONTENT")
    public 
String getContent() {
        return 
content;
    }
    public 
void setContent(String content) {
        
this.content content;
    }
}
 




Post a reply
  Related Posts  to : JPA entity class example
 @EntityListeners in your entity class     -  
 create a named query within entity class     -  
 Find entity by id     -  
 cmp entity beans     -  
 Get all objects for an entity     -  
 @Transient annotation in JPA entity     -  
 secondary table per entity     -  
 @Embeddable entity and @AttributeOverrides     -  
 JPA entity with table generator     -  
 Define class helper class to check the method existance     -  

Topic Tags

Java JPA