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

Hibernate example source code file (Luggage.java)

This example Hibernate source code file (Luggage.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

generatedvalue, id, integer, integer, io, joincolumn, joincolumn, joincolumns, luggage, luggage, onetomany, serializable, set, string, string, util

The Hibernate Luggage.java source code

//$Id$
package org.hibernate.test.annotations.referencedcolumnname;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.OneToMany;

/**
 * @author Emmanuel Bernard
 */
@Entity
public class Luggage implements Serializable {
	private Integer id;
	private String owner;
	private String type;
	private Set<Clothes> hasInside = new HashSet();

	public Luggage() {
	}

	public Luggage(String owner, String type) {
		this.owner = owner;
		this.type = type;
	}

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

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

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinColumns({
	@JoinColumn(name = "lug_type", referencedColumnName = "type"),
	@JoinColumn(name = "lug_owner", referencedColumnName = "owner")
			})
	public Set<Clothes> getHasInside() {
		return hasInside;
	}

	public void setHasInside(Set<Clothes> hasInside) {
		this.hasInside = hasInside;
	}

	public boolean equals(Object o) {
		if ( this == o ) return true;
		if ( !( o instanceof Luggage ) ) return false;

		final Luggage luggage = (Luggage) o;

		if ( !owner.equals( luggage.owner ) ) return false;
		if ( !type.equals( luggage.type ) ) return false;

		return true;
	}

	public int hashCode() {
		int result;
		result = owner.hashCode();
		result = 29 * result + type.hashCode();
		return result;
	}
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate Luggage.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.