1 /**
2 * Copyright 2005-2015 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krad.data.jpa;
17
18 import org.apache.commons.lang.builder.EqualsBuilder;
19 import org.apache.commons.lang.builder.HashCodeBuilder;
20 import org.apache.commons.lang.builder.ToStringBuilder;
21
22 import java.io.Serializable;
23
24 /**
25 * A base class for creating ID class implementations for JPA.
26 *
27 * <p>
28 * These ID classes are required to have proper equals and hashcode method implementations, so this base class provides
29 * reflection-based defaults for both of those as well as toString.
30 * </p>
31 *
32 * @see javax.persistence.IdClass
33 *
34 * @author Kuali Rice Team (rice.collab@kuali.org)
35 */
36 public abstract class IdClassBase implements Serializable {
37
38 private static final long serialVersionUID = -69571039682070713L;
39
40 /**
41 * {@inheritDoc}
42 */
43 @Override
44 public int hashCode() {
45 return HashCodeBuilder.reflectionHashCode(this);
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 @Override
52 public boolean equals(Object obj) {
53 return EqualsBuilder.reflectionEquals(obj, this);
54 }
55
56 /**
57 * {@inheritDoc}
58 */
59 @Override
60 public String toString() {
61 return ToStringBuilder.reflectionToString(this);
62 }
63
64 }