alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (Area.java)

This example Hibernate source code file (Area.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

area, entityresult, entityresult, fieldresult, fieldresult, generatedvalue, id, integer, night, night, sqlresultsetmappings, string, string, table

The Hibernate Area.java source code

//$Id$
package org.hibernate.test.annotations.query;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.FieldResult;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;

/**
 * Example of a entity load incl a join fetching of an associated *ToOne entity
 *
 * @author Emmanuel Bernard
 */
@Entity
@NamedNativeQueries({
@NamedNativeQuery(
		name = "night&area", query = "select night.id as nid, night.night_duration, night.night_date, area.id as aid, "
		+ "night.area_id, area.name from Night night, tbl_area area where night.area_id = area.id",
		resultSetMapping = "joinMapping")
		})
@org.hibernate.annotations.NamedNativeQueries({
@org.hibernate.annotations.NamedNativeQuery(
		name = "night&areaCached",
		query = "select night.id as nid, night.night_duration, night.night_date, area.id as aid, "
				+ "night.area_id, area.name from Night night, tbl_area area where night.area_id = area.id",
		resultSetMapping = "joinMapping")
		})
@SqlResultSetMappings(
		@SqlResultSetMapping(name = "joinMapping", entities = {
		@EntityResult(entityClass = org.hibernate.test.annotations.query.Night.class, fields = {
		@FieldResult(name = "id", column = "nid"),
		@FieldResult(name = "duration", column = "night_duration"),
		@FieldResult(name = "date", column = "night_date"),
		@FieldResult(name = "area", column = "area_id")
				}),
		@EntityResult(entityClass = org.hibernate.test.annotations.query.Area.class, fields = {
		@FieldResult(name = "id", column = "aid"),
		@FieldResult(name = "name", column = "name")
				})
				}
		)
)
@Table(name = "tbl_area")
public class Area {
	private Integer id;
	private String name;

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(unique = true)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate Area.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.