Search Java Code Snippets

  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.

#Java - Code Snippets for '#Hibernate' - 4 code snippet(s) found

 Sample 1. Hibernate Entity

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Type;

import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import org.hibernate.annotations.DiscriminatorOptions;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

@Table(name="Employee", schema = "test")
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
discriminatorType= DiscriminatorType.STRING
public class Employee {

@SequenceGenerator(name = "", sequenceName = "")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "")
private int employeeId;

private String employeeName;

private String department;

private Boolean isFullTime;

@Column(name = "ACTIVE")
@Type(type = "yes_no")
public boolean getActive() {
return active;

public String getName() {
return employeeName;

public String getDept() {
return department;

   Like      Feedback     Hibernate entity   Hibernate Bean

 Sample 2. Cache Hibernate Entities using EHCache

// net.sf.ehcache.Cache.Cache(String name, int maxElementsInMemory, MemoryStoreEvictionPolicy 
memoryStoreEvictionPolicy, boolean overflowToDisk, String diskStorePath, boolean eternal, long
timeToLiveSeconds, long timeToIdleSeconds, boolean diskPersistent, long
diskExpiryThreadIntervalSeconds, RegisteredEventListeners registeredEventListeners)

Ehcache employeeCache = new Cache("Employee", 1000, MemoryStoreEvictionPolicy.FIFO, false, "c:/EmployeeDiskCacheStorage", false, 300,
300, false, 30, null);

employeeCache = new SelfPopulatingCache(employeeCache, new CacheEntryFactory() {
   public Object createEntry(Object day) throws Exception {
      Employee employee = getEmployee(1234);
   return employee;


   Like      Feedback     EHCache  cache hibernate entities  CacheManager  CacheEntryFactory  SelfPopulatingCache  MemoryStoreEvictionPolicy  net.sf.ehcache.Cache

 Sample 3. Hibernate - Mapping the Id to RowId of Table ( workaround for Table having no primary key )

private String id;

   Like      Feedback     Hibernate  workaround for Table having no primary key  mapping Id to RowId

 Sample 4. Lazy Initialization using Hibernate

@Table(name = "EMPLOYEE")
public class Employee {
@ManyToOne(fetch = FetchType.LAZY)
private Set<Department> dept = new Department();

   Like      Feedback     Lazy Initialization using Hibernate

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner

comments powered by Disqus