com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId Maven / Gradle / Ivy
/*
* Copyright 2014 - 2019 Blazebit.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.blazebit.persistence.testsuite.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
@Embeddable
public class EmbeddableTestEntityId implements Serializable {
private static final long serialVersionUID = 1L;
private String value;
private String key;
public EmbeddableTestEntityId() {
}
public EmbeddableTestEntityId(String value, String key) {
this.value = value;
this.key = key;
}
// Fixed size because mysql has size limitations
@Column(name = "test_value", nullable = false, length = 10)
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
// Rename because mysql can't handle "key"
// Fixed size because mysql has size limitations
@Column(name = "test_key", nullable = false, length = 100)
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof EmbeddableTestEntityId)) {
return false;
}
EmbeddableTestEntityId that = (EmbeddableTestEntityId) o;
if (getValue() != null ? !getValue().equals(that.getValue()) : that.getValue() != null) {
return false;
}
return getKey() != null ? getKey().equals(that.getKey()) : that.getKey() == null;
}
@Override
public int hashCode() {
int result = getValue() != null ? getValue().hashCode() : 0;
result = 31 * result + (getKey() != null ? getKey().hashCode() : 0);
return result;
}
}