001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.data.jpa; 017 018import org.apache.commons.lang.builder.EqualsBuilder; 019import org.apache.commons.lang.builder.HashCodeBuilder; 020import org.apache.commons.lang.builder.ToStringBuilder; 021 022import java.io.Serializable; 023 024/** 025 * A base class for creating ID class implementations for JPA. 026 * 027 * <p> 028 * These ID classes are required to have proper equals and hashcode method implementations, so this base class provides 029 * reflection-based defaults for both of those as well as toString. 030 * </p> 031 * 032 * @see javax.persistence.IdClass 033 * 034 * @author Kuali Rice Team (rice.collab@kuali.org) 035 */ 036public abstract class IdClassBase implements Serializable { 037 038 private static final long serialVersionUID = -69571039682070713L; 039 040 /** 041 * {@inheritDoc} 042 */ 043 @Override 044 public int hashCode() { 045 return HashCodeBuilder.reflectionHashCode(this); 046 } 047 048 /** 049 * {@inheritDoc} 050 */ 051 @Override 052 public boolean equals(Object obj) { 053 return EqualsBuilder.reflectionEquals(obj, this); 054 } 055 056 /** 057 * {@inheritDoc} 058 */ 059 @Override 060 public String toString() { 061 return ToStringBuilder.reflectionToString(this); 062 } 063 064}