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

Hibernate example source code file (LineItem.java)

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

id, id, io, lineitem, lineitem, order, product, product, serializable, string, string

The Hibernate LineItem.java source code

//$Id: LineItem.java 4806 2004-11-25 14:37:00Z steveebersole $
package org.hibernate.test.cid;
import java.io.Serializable;

/**
 * @author Gavin King
 */
public class LineItem {
	public static class Id implements Serializable {
		private String customerId;
		private int orderNumber;
		private String productId;

		public Id(String customerId, int orderNumber, String productId) {
			this.customerId = customerId;
			this.orderNumber = orderNumber;
			this.productId = productId;
		}
		public Id() {}

		/**
		 * @return Returns the customerId.
		 */
		public String getCustomerId() {
			return customerId;
		}
		/**
		 * @param customerId The customerId to set.
		 */
		public void setCustomerId(String customerId) {
			this.customerId = customerId;
		}
		/**
		 * @return Returns the productId.
		 */
		public String getProductId() {
			return productId;
		}
		/**
		 * @param productId The productId to set.
		 */
		public void setProductId(String productId) {
			this.productId = productId;
		}
		/**
		 * @return Returns the orderNumber.
		 */
		public int getOrderNumber() {
			return orderNumber;
		}
		/**
		 * @param orderNumber The orderNumber to set.
		 */
		public void setOrderNumber(int orderNumber) {
			this.orderNumber = orderNumber;
		}
		public int hashCode() {
			return customerId.hashCode() + orderNumber + productId.hashCode();
		}
		public boolean equals(Object other) {
			if (other instanceof Id) {
				Id that = (Id) other;
				return that.customerId.equals(this.customerId) &&
					that.productId.equals(this.productId) &&
					that.orderNumber == this.orderNumber;
			}
			else {
				return false;
			}
		}
	}

	private Id id = new Id();
	private int quantity;
	private Order order;
	private Product product;

	public LineItem(Order o, Product p) {
		this.order = o;
		this.id.orderNumber = o.getId().getOrderNumber();
		this.id.customerId = o.getId().getCustomerId();
		this.id.productId = p.getProductId();
		o.getLineItems().add(this);
	}

	public LineItem() {}

	/**
	 * @return Returns the order.
	 */
	public Order getOrder() {
		return order;
	}
	/**
	 * @param order The order to set.
	 */
	public void setOrder(Order order) {
		this.order = order;
	}
	/**
	 * @return Returns the product.
	 */
	public Product getProduct() {
		return product;
	}
	/**
	 * @param product The product to set.
	 */
	public void setProduct(Product product) {
		this.product = product;
	}
	/**
	 * @return Returns the quantity.
	 */
	public int getQuantity() {
		return quantity;
	}
	/**
	 * @param quantity The quantity to set.
	 */
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
	/**
	 * @return Returns the id.
	 */
	public Id getId() {
		return id;
	}
	/**
	 * @param id The id to set.
	 */
	public void setId(Id id) {
		this.id = id;
	}
}

Other Hibernate examples (source code examples)

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