| /* |
| * Copyright (c) 2005, 2020 Oracle and/or its affiliates. All rights reserved. |
| * Copyright (c) 2005, 2015 SAP. All rights reserved. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0, |
| * or the Eclipse Distribution License v. 1.0 which is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
| */ |
| |
| // Contributors: |
| // SAP - initial API and implementation |
| |
| package org.eclipse.persistence.testing.models.wdf.jpa1.employee; |
| |
| import java.io.Serializable; |
| |
| import jakarta.persistence.Basic; |
| import jakarta.persistence.Cacheable; |
| import jakarta.persistence.ColumnResult; |
| import jakarta.persistence.Entity; |
| import jakarta.persistence.EntityResult; |
| import jakarta.persistence.FieldResult; |
| import jakarta.persistence.Id; |
| import jakarta.persistence.NamedNativeQueries; |
| import jakarta.persistence.NamedNativeQuery; |
| import jakarta.persistence.NamedQueries; |
| import jakarta.persistence.NamedQuery; |
| import jakarta.persistence.QueryHint; |
| import jakarta.persistence.SqlResultSetMapping; |
| import jakarta.persistence.SqlResultSetMappings; |
| import jakarta.persistence.Table; |
| import jakarta.persistence.Version; |
| |
| import org.eclipse.persistence.config.HintValues; |
| import org.eclipse.persistence.config.QueryHints; |
| |
| @Cacheable(true) |
| @Entity |
| @Table(name = "TMP_DEP") |
| @NamedQueries( { |
| @NamedQuery(name = "getAllDepartmentsCached", query = "select d from Department d", hints = { @QueryHint(name = QueryHints.QUERY_RESULTS_CACHE, value = HintValues.TRUE) }) , |
| @NamedQuery(name = "getDepartmentByName", query = "select d from Department d where d.name = ?1"), |
| @NamedQuery(name = "getDepartmentById", query = "select d from Department d where d.id = ?1"), |
| @NamedQuery(name = "getDepartmentUnCached", query = "select d from Department d where d.name = ?1", hints = { }), |
| @NamedQuery(name = "getDepartmentCached", query = "select d from Department d where d.name = ?1", hints = { @QueryHint(name = QueryHints.QUERY_RESULTS_CACHE, value = HintValues.TRUE) }) }) |
| @NamedNativeQueries( { |
| @NamedNativeQuery(name = "getDepartmentWithId10SQL_class", query = "select * from TMP_DEP D where D.ID = 10", resultClass = Department.class), |
| @NamedNativeQuery(name = "getDepartmentWithId10SQL_mapping", query = "select * from TMP_DEP D where D.ID = 10", resultSetMapping = "departmentByClass"), |
| @NamedNativeQuery(name = "getDepartmentName", query = "select name as \"HUTZLIPUTZ\" from TMP_DEP D where D.ID = 10", resultSetMapping = "departmentNameOnly"), |
| @NamedNativeQuery(name = "getDepartmentFieldByField", query = "select id as \"D_ID\", name as \"D_NAME\", version as \"D_VERSION\" from TMP_DEP D where D.ID = 10", resultSetMapping = "departmentByFields"), |
| @NamedNativeQuery(name = "getDepartmentFieldByField1", query = "select id as \"ID\", name as \"NAME\" from TMP_DEP D where D.ID = 1", resultSetMapping = "departmentByFields1") }) |
| @SqlResultSetMappings( { |
| @SqlResultSetMapping(name = "departmentByClass", entities = { @EntityResult(entityClass = Department.class) }), |
| @SqlResultSetMapping(name = "departmentNameOnly", columns = { @ColumnResult(name = "HUTZLIPUTZ") }), |
| @SqlResultSetMapping(name = "departmentByFields", entities = { @EntityResult(entityClass = Department.class, fields = { |
| @FieldResult(name = "id", column = "D_ID"), @FieldResult(name = "name", column = "D_NAME"), |
| @FieldResult(name = "version", column = "D_VERSION") }) }), |
| @SqlResultSetMapping(name = "departmentByFields1", columns = { @ColumnResult(name = "ID"), @ColumnResult(name = "NAME") }) }) |
| public class Department implements Serializable { |
| |
| public static final String HUGO = "hugo"; |
| |
| private static final long serialVersionUID = 1L; |
| |
| public void setId(int id) { |
| this._id = id; |
| } |
| |
| private int _id; |
| |
| private String _name; |
| |
| private short version; |
| |
| // this constructor should be protected |
| protected Department() { |
| } |
| |
| public Department(int aId, String aName) { |
| _id = aId; |
| _name = aName; |
| } |
| |
| @Id |
| public int getId() { |
| return _id; |
| } |
| |
| public void setName(String aName) { |
| _name = aName; |
| } |
| |
| @Basic |
| public String getName() { |
| return _name; |
| } |
| |
| @Version |
| public short getVersion() { |
| return version; |
| } |
| |
| // called by EntityManager |
| protected void setVersion(short newVersion) { |
| version = newVersion; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see java.lang.Object#equals(java.lang.Object) |
| */ |
| @Override |
| public boolean equals(Object obj) { |
| if (obj instanceof Department) { |
| Department other = (Department) obj; |
| if (_id != other._id) { |
| return false; |
| } |
| if (_name == null) { |
| return other._name == null; |
| } else { |
| return _name.equals(other._name); |
| } |
| } |
| return false; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see java.lang.Object#hashCode() |
| */ |
| @Override |
| public int hashCode() { |
| return _id; |
| } |
| |
| public Object writeReplace() { |
| Department copy = new Department(); |
| copy._id = _id; |
| copy._name = HUGO; |
| copy.version = version; |
| return copy; |
| } |
| |
| public static class KrassDep extends Department { |
| private static final long serialVersionUID = 1L; |
| private final String gnubbelWurst; |
| |
| public KrassDep(String gnubbelWurst) { |
| super(); |
| this.gnubbelWurst = gnubbelWurst; |
| } |
| |
| public String getGnubbelWurst() { |
| return gnubbelWurst; |
| } |
| } |
| } |