/*******************************************************************************
* Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
/*******************************************************************************
* Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
package org.eclipse.persistence.testing.models.jpa.xml.merge.incompletemappings.owning;
import java.util.*;
import java.io.Serializable;
import javax.persistence.*;
import static javax.persistence.GenerationType.*;
import static javax.persistence.CascadeType.*;
import static javax.persistence.FetchType.*;
/**
*
*/
@Entity(name="XMLIncompleteMergeEmplyee")
@Table(name="CMP3_XML_MERGE_EMPLOYEE")
@PrimaryKeyJoinColumn(name="EMP_ID", referencedColumnName="EMP_ID")
public class Employee implements Serializable {
private Integer id;
private int version;
private String firstName;
private String lastName;
private Address address;
private Collection<PhoneNumber> phoneNumbers;
private Collection<Project> projects;
private Collection<Employee> managedEmployees;
private Employee manager;
private SecurityBadge securityBadge;
public Employee () {
this.phoneNumbers = new Vector<PhoneNumber>();
this.projects = new Vector<Project>();
this.managedEmployees = new Vector<Employee>();
}
public Employee(String firstName, String lastName){
this();
this.firstName = firstName;
this.lastName = lastName;
}
@Id
@GeneratedValue(strategy=TABLE, generator="XML_MERGE_EMPLOYEE_TABLE_GENERATOR")
@TableGenerator(
name="XML_MERGE_EMPLOYEE_TABLE_GENERATOR",
table="CMP3_XML_MERGE_EMPLOYEE_SEQ",
pkColumnName="SEQ_NAME",
valueColumnName="SEQ_COUNT",
pkColumnValue="XML_MERGE_EMPLOYEE_SEQ"
)
@Column(name="EMP_ID")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Version
@Column(name="VERSION")
public int getVersion() {
return version;
}
protected void setVersion(int version) {
this.version = version;
}
@Column(name="F_NAME")
public String getFirstName() {
return firstName;
}
public void setFirstName(String name) {
this.firstName = name;
}
@Column(name="L_NAME")
public String getLastName() {
return lastName;
}
public void setLastName(String name) {
this.lastName = name;
}
@ManyToOne(cascade=PERSIST, fetch=LAZY)
@JoinColumn(name="ADDR_ID")
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
@OneToMany(cascade=ALL, mappedBy="owner")
public Collection<PhoneNumber> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(Collection<PhoneNumber> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}
// the @JoinColumn will be ignored, as it is partially defined in XML
@OneToOne
@JoinColumn(name="SECURITYBADGE_BADGE_ID", referencedColumnName="BADGE_ID")
public SecurityBadge getSecurityBadge() {
return securityBadge;
}
public void setSecurityBadge(SecurityBadge securityBadge) {
this.securityBadge = securityBadge;
}
@OneToMany(cascade=ALL, mappedBy="manager")
public Collection<Employee> getManagedEmployees() {
return managedEmployees;
}
public void setManagedEmployees(Collection<Employee> managedEmployees) {
this.managedEmployees = managedEmployees;
}
// Not defined in the XML, this should get processed.
@ManyToOne(cascade=PERSIST, fetch=LAZY)
public Employee getManager() {
return manager;
}
public void setManager(Employee manager) {
this.manager = manager;
}
@ManyToMany(cascade=PERSIST)
@JoinTable(
name="CMP3_XML_MERGE_PROJ_EMP",
// Default for the project side and specify for the employee side
// Will test both defaulting and set values.
joinColumns=@JoinColumn(name="EMPLOYEES_EMP_ID", referencedColumnName="EMP_ID")
//inverseJoinColumns=@JoinColumn(name="PROJECTS_PROJ_ID", referencedColumnName="PROJ_ID")
)
public Collection<Project> getProjects() {
return projects;
}
public void setProjects(Collection<Project> projects) {
this.projects = projects;
}
public void addManagedEmployee(Employee emp) {
getManagedEmployees().add(emp);
emp.setManager(this);
}
public void addPhoneNumber(PhoneNumber phone) {
phone.setOwner(this);
getPhoneNumbers().add(phone);
}
public void addProject(Project theProject) {
getProjects().add(theProject);
}
public String toString() {
return "Employee: " + getId();
}
}