Switch to full style
Java persistent API
Post a reply

cascade=CascadeType.REFRESH with many to one relation

Sun May 09, 2010 9:35 pm

If any entity x related to entity y . and x refresh function called , y refresh function is called automatically. refresh means reload the values from database .

Code:

package com
.codemiles.jpa;

import java.util.Collection;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToMany;
@
Entity
@Table(name="COURSE")
public class 
Course implements java.io.Serializable{
    
/**
     * 
     */
    
private static final long serialVersionUID 1L;
    @
Id
    
private long Id;
    private 
String name;
    private 
Long credit;
    private 
Date startDate;
    private 
String department;
    @
OneToMany(mappedBy="course",cascade=CascadeType.REFRESH)
    private 
Collection<Student_Coursestudent_courses;
 
    public  
long getId() {
        return 
Id;
    }
    public 
void setIdlong id) {
        
Id id;
    }
    @
Column(name="NAME")
    public 
String getName() {
        return 
name;
    }
    public 
void setName(String name) {
        
this.name name;
    }
    @
Column(name="CREDIT")
    public 
Long getCredit() {
        return 
credit;
    }
    public 
void setCredit(Long credit) {
        
this.credit credit;
    }
    @
Column(name="START_DATE")
    public 
Date getStartDate() {
        return 
startDate;
    }
    public 
void setStartDate(Date startDate) {
        
this.startDate startDate;
    }
    @
Column(name="DEPARTMENT")
    public 
String getDepartment() {
        return 
department;
    }
    public 
void setDepartment(String department) {
        
this.department department;
    }
    public 
void setStudent_courses(Collection<Student_Coursestudent_courses) {
    
this.student_courses student_courses;
    }
    public 
Collection<Student_CoursegetStudent_courses() {
    return 
student_courses;
    }
   
}

 




Post a reply
  Related Posts  to : cascade=CascadeType.REFRESH with many to one relation
 one to many relation JPA example     -  
 Cascade.All and persisting related entities directly     -  

Topic Tags

Java JPA