| /* |
| * Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved. |
| * Copyright (c) 2011, 2015 Karsten Wutzke. 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: |
| // 01/04/2011-2.3 Guy Pelletier for Karsten Wutzke |
| // - 330628: @PrimaryKeyJoinColumn(...) is not working equivalently to @JoinColumn(..., insertable = false, updatable = false) |
| package org.eclipse.persistence.testing.models.jpa.ddlgeneration; |
| |
| import java.io.Serializable; |
| import jakarta.persistence.Column; |
| import jakarta.persistence.Entity; |
| import jakarta.persistence.Id; |
| import jakarta.persistence.IdClass; |
| import jakarta.persistence.ManyToOne; |
| import jakarta.persistence.PrimaryKeyJoinColumn; |
| import jakarta.persistence.PrimaryKeyJoinColumns; |
| import jakarta.persistence.Table; |
| |
| @Entity |
| @Table(name = "ZipAreas") |
| @IdClass(value = ZipAreaId.class) |
| public class ZipArea implements Serializable |
| { |
| @Id |
| @Column(name = "country_code") |
| private String countryCode; |
| |
| @Id |
| @Column(name = "zip_code") |
| private String zipCode; |
| |
| @Id |
| @Column(name = "state_code") |
| private String stateCode; |
| |
| @Id |
| @Column(name = "city_name") |
| private String cityName; |
| |
| @ManyToOne |
| @PrimaryKeyJoinColumns(value = {@PrimaryKeyJoinColumn(name = "country_code", referencedColumnName = "country_code"), @PrimaryKeyJoinColumn(name = "zip_code", referencedColumnName = "code")}) |
| private Zip zip = null; |
| |
| @ManyToOne |
| @PrimaryKeyJoinColumns(value = {@PrimaryKeyJoinColumn(name = "country_code", referencedColumnName = "country_code"), @PrimaryKeyJoinColumn(name = "state_code", referencedColumnName = "state_code"), @PrimaryKeyJoinColumn(name = "city_name", referencedColumnName = "name")}) |
| private City city = null; |
| |
| public ZipArea() |
| { |
| } |
| |
| public ZipArea(String countryCode, String zipCode, String stateCode, String cityName) |
| { |
| this.countryCode = countryCode; |
| this.zipCode = zipCode; |
| this.stateCode = stateCode; |
| this.cityName = cityName; |
| |
| if ( countryCode != null && zipCode != null ) |
| { |
| this.zip = new Zip(countryCode, zipCode); |
| } |
| |
| if ( countryCode != null && stateCode != null && cityName != null ) |
| { |
| this.city = new City(countryCode, stateCode, cityName); |
| } |
| } |
| |
| public String getCountryCode() |
| { |
| return countryCode; |
| } |
| |
| public String getZipCode() |
| { |
| return zipCode; |
| } |
| |
| public String getStateCode() |
| { |
| return stateCode; |
| } |
| |
| public String getCityName() |
| { |
| return cityName; |
| } |
| |
| public Zip getZip() |
| { |
| return zip; |
| } |
| |
| public void setZip(Zip zip) |
| { |
| this.zip = zip; |
| this.countryCode = zip.getCountryCode(); |
| this.zipCode = zip.getCode(); |
| } |
| |
| public City getCity() |
| { |
| return city; |
| } |
| |
| public void setCity(City city) |
| { |
| this.city = city; |
| this.countryCode = city.getCountryCode(); |
| this.stateCode = city.getStateCode(); |
| this.cityName = city.getName(); |
| } |
| } |