Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 249144 Details for
Bug 395738
Bad row mapping when join fetching an abstract entity with column discriminator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
jUnit tests integrated into EclipseLink
0002-Bug-395738-Bad-row-mapping-when-join-fetching-an-abs.patch (text/plain), 35.85 KB, created by
Tomas Kraus
on 2014-12-03 13:18:23 EST
(
hide
)
Description:
jUnit tests integrated into EclipseLink
Filename:
MIME Type:
Creator:
Tomas Kraus
Created:
2014-12-03 13:18:23 EST
Size:
35.85 KB
patch
obsolete
>From ccc536e1b6e0cb112c8979b874785823b9c51c84 Mon Sep 17 00:00:00 2001 >From: Tomas Kraus <tomas.kraus@oracle.com> >Date: Wed, 3 Dec 2014 19:09:43 +0100 >Subject: [PATCH 2/2] Bug 395738 - Bad row mapping when join fetching an > abstract entity with column discriminator jUnit tests Based on > standalone tests by J LM<jlamande@gmail.com> > >--- > jpa/eclipselink.jpa.test/antbuild.xml | 1 + > .../osgi/persistence.xml | 20 ++ > .../eclipselink-annotation-model/persistence.xml | 20 ++ > .../spring/persistence.xml | 20 ++ > .../models/jpa/advanced/customer/AddressType1.java | 72 ++++++ > .../models/jpa/advanced/customer/AddressType2.java | 71 ++++++ > .../customer/AdvancedCustomerTableCreator.java | 62 +++++ > .../jpa/advanced/customer/CustomerAddress.java | 54 +++++ > .../jpa/advanced/customer/RegisteredCustomer.java | 156 +++++++++++++ > .../AbstractEntityWithColumnDiscriminatorTest.java | 260 +++++++++++++++++++++ > 10 files changed, 736 insertions(+) > create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AddressType1.java > create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AddressType2.java > create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AdvancedCustomerTableCreator.java > create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/CustomerAddress.java > create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/RegisteredCustomer.java > create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/advanced/AbstractEntityWithColumnDiscriminatorTest.java > >diff --git a/jpa/eclipselink.jpa.test/antbuild.xml b/jpa/eclipselink.jpa.test/antbuild.xml >index 3338765..17dee2f 100644 >--- a/jpa/eclipselink.jpa.test/antbuild.xml >+++ b/jpa/eclipselink.jpa.test/antbuild.xml >@@ -843,6 +843,7 @@ > org/eclipse/persistence/testing/models/jpa/cacheable/** > org/eclipse/persistence/testing/models/jpa/cascadedeletes/** > org/eclipse/persistence/testing/models/jpa/complexaggregate/** >+ org/eclipse/persistence/testing/models/jpa/customer/** > org/eclipse/persistence/testing/models/jpa/datatypes/** > org/eclipse/persistence/testing/models/jpa/datetime/** > org/eclipse/persistence/testing/models/jpa/inheritance/** >diff --git a/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/osgi/persistence.xml b/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/osgi/persistence.xml >index f4badd5..d7008d8 100644 >--- a/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/osgi/persistence.xml >+++ b/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/osgi/persistence.xml >@@ -142,4 +142,24 @@ > <exclude-unlisted-classes>true</exclude-unlisted-classes> > <shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode> > </persistence-unit> >+ >+ <!-- Advanced customer model persistence unit. --> >+ <persistence-unit name="customer-pu" transaction-type="RESOURCE_LOCAL"> >+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> >+ <shared-cache-mode>NONE</shared-cache-mode> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.CustomerAddress</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.AddressType1</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.AddressType2</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.RegisteredCustomer</class> >+ <exclude-unlisted-classes>true</exclude-unlisted-classes> >+ <properties> >+ <property name="eclipselink.logging.level" value="FINE" /> >+ <property name="eclipselink.logging.level.sql" value="FINEST"/> >+ <property name="eclipselink.logging.level.cache" value="FINEST" /> >+ <property name="eclipselink.logging.parameters" value="true"/> >+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> >+ <property name="eclipselink.ddl-generation.output-mode" value="database" /> >+ </properties> >+ </persistence-unit> >+ > </persistence> >diff --git a/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/persistence.xml b/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/persistence.xml >index 111f291..87847d2 100644 >--- a/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/persistence.xml >+++ b/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/persistence.xml >@@ -403,4 +403,24 @@ > <property name="eclipselink.validation-only" value="true"/> > </properties> > </persistence-unit> >+ >+ <!-- Advanced customer model persistence unit. --> >+ <persistence-unit name="customer-pu" transaction-type="RESOURCE_LOCAL"> >+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> >+ <shared-cache-mode>NONE</shared-cache-mode> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.CustomerAddress</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.AddressType1</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.AddressType2</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.RegisteredCustomer</class> >+ <exclude-unlisted-classes>true</exclude-unlisted-classes> >+ <properties> >+ <property name="eclipselink.logging.level" value="FINE" /> >+ <property name="eclipselink.logging.level.sql" value="FINEST"/> >+ <property name="eclipselink.logging.level.cache" value="FINEST" /> >+ <property name="eclipselink.logging.parameters" value="true"/> >+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> >+ <property name="eclipselink.ddl-generation.output-mode" value="database" /> >+ </properties> >+ </persistence-unit> >+ > </persistence> >diff --git a/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/spring/persistence.xml b/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/spring/persistence.xml >index d68b134..99041de 100644 >--- a/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/spring/persistence.xml >+++ b/jpa/eclipselink.jpa.test/resource/eclipselink-annotation-model/spring/persistence.xml >@@ -216,4 +216,24 @@ > <property name="eclipselink.session-name" value="additional-criteria"/> > </properties> > </persistence-unit> >+ >+ <!-- Advanced customer model persistence unit. --> >+ <persistence-unit name="customer-pu" transaction-type="RESOURCE_LOCAL"> >+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> >+ <shared-cache-mode>NONE</shared-cache-mode> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.CustomerAddress</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.AddressType1</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.AddressType2</class> >+ <class>org.eclipse.persistence.testing.models.jpa.advanced.customer.RegisteredCustomer</class> >+ <exclude-unlisted-classes>true</exclude-unlisted-classes> >+ <properties> >+ <property name="eclipselink.logging.level" value="FINE" /> >+ <property name="eclipselink.logging.level.sql" value="FINEST"/> >+ <property name="eclipselink.logging.level.cache" value="FINEST" /> >+ <property name="eclipselink.logging.parameters" value="true"/> >+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> >+ <property name="eclipselink.ddl-generation.output-mode" value="database" /> >+ </properties> >+ </persistence-unit> >+ > </persistence> >diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AddressType1.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AddressType1.java >new file mode 100644 >index 0000000..7bcd0ab >--- /dev/null >+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AddressType1.java >@@ -0,0 +1,72 @@ >+/******************************************************************************* >+ * Copyright (c) 2014 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: >+ * jlamande - Initial API and implementation >+ * Tomas Kraus - EclipseLink jUnit tests integration >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.models.jpa.advanced.customer; >+ >+import javax.persistence.Column; >+import javax.persistence.DiscriminatorValue; >+import javax.persistence.Entity; >+ >+/** >+ * First abstract {@link CustomerAddress} entity offspring. >+ */ >+@Entity >+@DiscriminatorValue("1") >+public class AddressType1 extends CustomerAddress { >+ >+ /** Street name. */ >+ @Column(name="STREET1") >+ private String street1; >+ >+ /** >+ * Creates an instance of first {@link CustomerAddress} entity offspring. No entity attributes are set. >+ */ >+ public AddressType1() { >+ } >+ >+ /** >+ * Creates an instance of first {@link CustomerAddress} entity offspring. >+ * @param street Street name to be set. >+ */ >+ public AddressType1(final String street) { >+ street1 = street; >+ } >+ >+ /** >+ * Get street name. >+ * @return Street name attribute value. >+ */ >+ @Override >+ public String getStreet() { >+ return street1; >+ } >+ >+ /** >+ * Set street name. >+ * @param street Street name to be set. >+ */ >+ @Override >+ public void setStreet(final String street) { >+ street1 = street; >+ } >+ >+ /** >+ * Return first {@link CustomerAddress} entity offspring in human readable form. >+ * @return Entity converted to {@link String} in human readable form. >+ */ >+ @Override >+ public String toString() { >+ return "AddressType1 [" + street1 + "]"; >+ } >+ >+} >diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AddressType2.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AddressType2.java >new file mode 100644 >index 0000000..62ca44f >--- /dev/null >+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AddressType2.java >@@ -0,0 +1,71 @@ >+/******************************************************************************* >+ * Copyright (c) 2014 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: >+ * jlamande - Initial API and implementation >+ * Tomas Kraus - EclipseLink jUnit tests integration >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.models.jpa.advanced.customer; >+ >+import javax.persistence.Column; >+import javax.persistence.DiscriminatorValue; >+import javax.persistence.Entity; >+ >+/** >+ * Second abstract {@link CustomerAddress} entity offspring. >+ */ >+@Entity >+@DiscriminatorValue("2") >+public class AddressType2 extends CustomerAddress { >+ >+ /** Street name. */ >+ @Column(name="STREET2") >+ private String street2; >+ >+ /** >+ * Creates an instance of second {@link CustomerAddress} entity offspring. No entity attributes are set. >+ */ >+ public AddressType2() { >+ } >+ >+ /** >+ * Creates an instance of second {@link CustomerAddress} entity offspring. >+ * @param street Street name to be set. >+ */ >+ public AddressType2(final String street) { >+ this.street2 = street; >+ } >+ >+ /** >+ * Get street name. >+ * @return Street name attribute value. >+ */ >+ @Override >+ public String getStreet() { >+ return street2; >+ } >+ >+ /** >+ * Set street name. >+ * @param street Street name to be set. >+ */ >+ @Override >+ public void setStreet(final String street) { >+ street2 = street; >+ } >+ >+ /** >+ * Return secomd {@link CustomerAddress} entity offspring in human readable form. >+ * @return Entity converted to {@link String} in human readable form. >+ */ >+ @Override >+ public String toString() { >+ return "AddressType2 [" + street2 + "]"; >+ } >+} >diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AdvancedCustomerTableCreator.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AdvancedCustomerTableCreator.java >new file mode 100644 >index 0000000..5514094 >--- /dev/null >+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/AdvancedCustomerTableCreator.java >@@ -0,0 +1,62 @@ >+/******************************************************************************* >+ * Copyright (c) 2014 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: >+ * Tomas Kraus - Initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.models.jpa.advanced.customer; >+ >+import org.eclipse.persistence.testing.framework.TogglingFastTableCreator; >+import org.eclipse.persistence.tools.schemaframework.TableDefinition; >+ >+// This table creator class is not used in the tests. Persistence unit shall create tables itself because of having >+// eclipselink.ddl-generation value set to drop-and-create-tables. >+// TODO: Resolve sequence / auto increment for primary keys. This is not implemented yet in this table creator. >+/** >+ * Advanced customer model table creator. >+ */ >+public class AdvancedCustomerTableCreator extends TogglingFastTableCreator { >+ >+ /** >+ * Build Address entity table definition including DiscriminatorColumn and offspring columns. >+ * @return Address entity table definition. >+ */ >+ public static TableDefinition buildAddressTable() { >+ TableDefinition table = createTable("CMP3_AD_CU_ADDRESS"); >+ table.addField(createNumericPk("ID")); >+ table.addField(createNumericColumn("TYPE", 1, false)); >+ table.addField(createStringColumn("STREET1")); >+ table.addField(createStringColumn("STREET2")); >+ return table; >+ } >+ >+ /** >+ * Build Customer entity table definition. >+ * @return Customer entity table definition. >+ */ >+ public static TableDefinition buildCustomerTable() { >+ TableDefinition table = createTable("CMP3_AD_CU_ADDRESS"); >+ table.addField(createNumericPk("ID")); >+ table.addField(createStringColumn("NAME", 1, false)); >+ table.addField(createNumericFk("ADDR_BA_ID", "ID")); >+ table.addField(createNumericFk("ADDR_DA_ID", "ID")); >+ return table; >+ } >+ >+ /** >+ * Crates an instance of advanced customer model table creator. >+ * All model table definitions are registered. >+ */ >+ public AdvancedCustomerTableCreator() { >+ setName("EJB3AdvancedCustomerProject"); >+ addTableDefinition(buildAddressTable()); >+ addTableDefinition(buildCustomerTable()); >+ } >+ >+} >diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/CustomerAddress.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/CustomerAddress.java >new file mode 100644 >index 0000000..bafbfbe >--- /dev/null >+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/CustomerAddress.java >@@ -0,0 +1,54 @@ >+/******************************************************************************* >+ * Copyright (c) 2014 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: >+ * jlamande - Initial API and implementation >+ * Tomas Kraus - EclipseLink jUnit tests integration >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.models.jpa.advanced.customer; >+ >+import javax.persistence.Column; >+import javax.persistence.DiscriminatorColumn; >+import javax.persistence.Entity; >+import javax.persistence.GeneratedValue; >+import javax.persistence.GenerationType; >+import javax.persistence.Id; >+import javax.persistence.Inheritance; >+import javax.persistence.SequenceGenerator; >+import javax.persistence.Table; >+ >+/** >+ * Abstract customer's address entity. >+ */ >+@Entity >+@Table(name="CMP3_AD_CU_ADDRESS") >+@Inheritance >+@DiscriminatorColumn(name="TYPE",length=1) >+@SequenceGenerator(name="CMP3_AD_CU_ADDRESS_ID_SEQ") >+public abstract class CustomerAddress { >+ >+ /** Address primary key. */ >+ @Id >+ @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="CMP3_AD_CU_ADDRESS_ID_SEQ") >+ @Column(name="ID") >+ private long id; >+ >+ /** >+ * Get street name. >+ * @return Street name attribute value. >+ */ >+ public abstract String getStreet(); >+ >+ /** >+ * Set street name. >+ * @param street Street name to be set. >+ */ >+ public abstract void setStreet(final String street); >+ >+} >diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/RegisteredCustomer.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/RegisteredCustomer.java >new file mode 100644 >index 0000000..4892ffa >--- /dev/null >+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/customer/RegisteredCustomer.java >@@ -0,0 +1,156 @@ >+/******************************************************************************* >+ * Copyright (c) 2014 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: >+ * jlamande - Initial API and implementation >+ * Tomas Kraus - EclipseLink jUnit tests integration >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.models.jpa.advanced.customer; >+ >+import javax.persistence.CascadeType; >+import javax.persistence.Column; >+import javax.persistence.Entity; >+import javax.persistence.GeneratedValue; >+import javax.persistence.GenerationType; >+import javax.persistence.Id; >+import javax.persistence.JoinColumn; >+import javax.persistence.NamedQueries; >+import javax.persistence.NamedQuery; >+import javax.persistence.OneToOne; >+import javax.persistence.SequenceGenerator; >+import javax.persistence.Table; >+ >+/** >+ * Customer entity. >+ */ >+@Entity >+@Table(name="CMP3_AD_CU_CUSTOMER") >+@SequenceGenerator(name="CMP3_AD_CU_CUSTOMER_ID_SEQ") >+@NamedQueries({ >+ @NamedQuery(name="RegisteredCustomer.selecAll", >+ query="SELECT c FROM RegisteredCustomer c"), >+ >+ @NamedQuery(name="RegisteredCustomer.selecByName", >+ query="SELECT c FROM RegisteredCustomer c" >+ + " WHERE c.name = :name"), >+ >+ @NamedQuery(name="RegisteredCustomer.selecByNameFetch", >+ query="SELECT c FROM RegisteredCustomer c" >+ + " LEFT JOIN FETCH c.deliveryAddress" >+ + " LEFT JOIN FETCH c.billingAddress" >+ + " WHERE c.name = :name") >+}) >+public class RegisteredCustomer { >+ >+ /** Customer primary key. */ >+ @Id >+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="CMP3_AD_CU_CUSTOMER_ID_SEQ") >+ @Column(name="ID") >+ private long id; >+ >+ /** Customer name. */ >+ @Column(name="NAME") >+ private String name; >+ >+ /** Customer billing address. */ >+ @OneToOne(cascade=CascadeType.ALL) >+ @JoinColumn(name="ADDR_BA_ID", referencedColumnName="ID") >+ private CustomerAddress billingAddress; >+ >+ /** Customer delivery address. */ >+ @OneToOne(cascade=CascadeType.ALL) >+ @JoinColumn(name="ADDR_DA_ID", referencedColumnName="ID") >+ private CustomerAddress deliveryAddress; >+ >+ /** >+ * Creates an instance of {@code RegisteredCustomer} entity. >+ * No entity attributes are set. >+ */ >+ public RegisteredCustomer() { >+ } >+ >+ /** >+ * Creates an instance of {@code RegisteredCustomer} entity. >+ * @param name Customer name to be set. >+ * @param billingAddress Customer billing address to be set. >+ * @param deliveryAddress Customer delivery address to be set. >+ */ >+ public RegisteredCustomer(final String name, final CustomerAddress billingAddress, >+ final CustomerAddress deliveryAddress) { >+ this.name = name; >+ this.billingAddress = billingAddress; >+ this.deliveryAddress = deliveryAddress; >+ } >+ >+ /** >+ * Get Customer primary key. >+ * @return Customer primary key attribute value. >+ */ >+ public long getId() { >+ return id; >+ } >+ >+ /** >+ * Get Customer name. >+ * @return Customer name attribute value. >+ */ >+ public String getName() { >+ return name; >+ } >+ >+ /** >+ * Set Customer name. >+ * @return Customer name to be set. >+ */ >+ public void setName(final String name) { >+ this.name = name; >+ } >+ >+ /** >+ * Get Customer billing address. >+ * @return Customer billing address attribute value. >+ */ >+ public CustomerAddress getBillingAddress() { >+ return billingAddress; >+ } >+ >+ /** >+ * Set Customer billing address. >+ * @param billingAddress Customer billing address to be set. >+ */ >+ public void setBillingAddress(final CustomerAddress billingAddress) { >+ this.billingAddress = billingAddress; >+ } >+ >+ /** >+ * Get Customer delivery address. >+ * @return Customer delivery address attribute value. >+ */ >+ public CustomerAddress getDeliveryAddress() { >+ return deliveryAddress; >+ } >+ >+ /** >+ * Set Customer delivery address. >+ * @param deliveryAddress Customer delivery address to be set. >+ */ >+ public void setDeliveryAddress(final CustomerAddress deliveryAddress) { >+ this.deliveryAddress = deliveryAddress; >+ } >+ >+ /** >+ * Return Customer entity in human readable form. >+ * @return Entity converted to {@link String} in human readable form. >+ */ >+ @Override >+ public String toString() { >+ return "RegisteredCustomer [" + id + "," + name + "," + billingAddress + "," + deliveryAddress + "]"; >+ } >+ >+} >diff --git a/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/advanced/AbstractEntityWithColumnDiscriminatorTest.java b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/advanced/AbstractEntityWithColumnDiscriminatorTest.java >new file mode 100644 >index 0000000..731c0f5 >--- /dev/null >+++ b/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/advanced/AbstractEntityWithColumnDiscriminatorTest.java >@@ -0,0 +1,260 @@ >+/******************************************************************************* >+ * Copyright (c) 2014 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: >+ * jlamande - Initial API and implementation >+ * Tomas Kraus - EclipseLink jUnit tests integration >+ ******************************************************************************/ >+package org.eclipse.persistence.testing.tests.jpa.advanced; >+ >+import java.util.List; >+ >+import javax.persistence.EntityManager; >+import javax.persistence.Query; >+import javax.persistence.TypedQuery; >+import javax.persistence.criteria.CriteriaBuilder; >+import javax.persistence.criteria.CriteriaQuery; >+import javax.persistence.criteria.JoinType; >+import javax.persistence.criteria.Root; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+ >+import org.eclipse.persistence.testing.framework.junit.JUnitTestCase; >+import org.eclipse.persistence.testing.models.jpa.advanced.AdvancedTableCreator; >+import org.eclipse.persistence.testing.models.jpa.advanced.customer.CustomerAddress; >+import org.eclipse.persistence.testing.models.jpa.advanced.customer.AddressType1; >+import org.eclipse.persistence.testing.models.jpa.advanced.customer.AddressType2; >+import org.eclipse.persistence.testing.models.jpa.advanced.customer.AdvancedCustomerTableCreator; >+import org.eclipse.persistence.testing.models.jpa.advanced.customer.RegisteredCustomer; >+ >+/** >+ * Runs tests on advanced customer model with Customer entity having two abstract Addresses. Each of those addresses >+ * may contain instances of different offspring. Address entities are mapped into a single table using >+ * {@code DiscriminatorColumn} to distinguish them. >+ */ >+public class AbstractEntityWithColumnDiscriminatorTest extends JUnitTestCase { >+ >+ /** {@link RegisteredCustomer} entity name attribute value. */ >+ private static final String CUSTOMER_NAME = "JONES"; >+ >+ /** Value of {@code billingAddress} entity street attribute. */ >+ private static final String CUSTOMER_ADDR_BILLING = "STREET1"; >+ >+ /** Value of {@code deliveryAddress} entity street attribute. */ >+ private static final String CUSTOMER_ADDR_DELIVERY = "STREET2"; >+ >+ >+ /** Persistence unit name. */ >+ private static final String PU_NAME = "customer-pu"; >+ >+ /** >+ * Build collection of test cases for this jUnit test instance. >+ * @return {@link Test} class containing collection of test cases for this jUnit test instance. >+ */ >+ public static Test suite() { >+ final TestSuite suite = new TestSuite(); >+ suite.addTest(new AbstractEntityWithColumnDiscriminatorTest("testSetup")); >+ addNamedQueryTests(suite); >+ suite.addTest(new AbstractEntityWithColumnDiscriminatorTest("testCleanup")); >+ return suite; >+ } >+ >+ /** >+ * Adds test, similar to suite() but without adding a setup and cleanup. Used from {@code suite()} to add individual >+ * tests. >+ * @param suite Target {@link TestSuite} class where to store tests. >+ * @return {@link Test} class containing collection of test cases for this jUnit test instance. >+ */ >+ public static Test addNamedQueryTests(final TestSuite suite){ >+ suite.setName("NamedQueryJUnitTest"); >+ suite.addTest(new AbstractEntityWithColumnDiscriminatorTest("testJpqlNoFetch")); >+ suite.addTest(new AbstractEntityWithColumnDiscriminatorTest("testJpqlFetch")); >+ suite.addTest(new AbstractEntityWithColumnDiscriminatorTest("testCriteriaNoFetch")); >+ suite.addTest(new AbstractEntityWithColumnDiscriminatorTest("testCriteriaFetch")); >+ return suite; >+ } >+ >+ /** >+ * Create {@link RegisteredCustomer} entity instance with {@code billingAddress} set to {@link AddressType1} >+ * instance and {@code deliveryAddress} set to {@link AddressType2} instance. Entity is persisted. >+ * @param em An {@link EntityManager} instance used to persist entities. >+ */ >+ private static void createCustomer(final EntityManager em) { >+ em.getTransaction().begin(); >+ try { >+ final RegisteredCustomer cus = new RegisteredCustomer(CUSTOMER_NAME, new AddressType1( >+ CUSTOMER_ADDR_BILLING), new AddressType2(CUSTOMER_ADDR_DELIVERY)); >+ em.persist(cus); >+ em.getTransaction().commit(); >+ } catch (Throwable e) { >+ em.getTransaction().rollback(); >+ throw e; >+ } >+ } >+ >+ /** >+ * Delete all {@link RegisteredCustomer} entities. >+ * @param em An {@link EntityManager} instance used to persist entities. >+ */ >+ private static void deleteAllCustomers(final EntityManager em) { >+ List<RegisteredCustomer> customers = em.createNamedQuery( >+ "RegisteredCustomer.selecAll", RegisteredCustomer.class).getResultList(); >+ em.getTransaction().begin(); >+ try { >+ for (RegisteredCustomer cus : customers) { >+ em.remove(cus); >+ } >+ em.getTransaction().commit(); >+ } catch (Throwable e) { >+ em.getTransaction().rollback(); >+ throw e; >+ } >+ } >+ >+ /** >+ * Validate {@link RegisteredCustomer} entity instance. >+ * @param customer {@link RegisteredCustomer} entity instance to be validated. >+ */ >+ private static void assertCustomer(final RegisteredCustomer customer) { >+ assertEquals(CUSTOMER_NAME, customer.getName()); >+ assertTrue(customer.getBillingAddress() instanceof AddressType1); >+ assertEquals(CUSTOMER_ADDR_BILLING, ((AddressType1) customer.getBillingAddress()).getStreet()); >+ assertTrue(customer.getDeliveryAddress() instanceof AddressType2); >+ assertEquals(CUSTOMER_ADDR_DELIVERY, ((AddressType2) customer.getDeliveryAddress()).getStreet()); >+ } >+ >+ /** >+ * Constructs an instance of {@code AbstractEntityWithColumnDiscriminatorTest} class. >+ */ >+ public AbstractEntityWithColumnDiscriminatorTest() { >+ super(); >+ } >+ >+ /** >+ * Constructs an instance of {@code AbstractEntityWithColumnDiscriminatorTest} class with given test case name. >+ * @param name Test case name. >+ */ >+ public AbstractEntityWithColumnDiscriminatorTest(final String name) { >+ super(name); >+ setPuName(PU_NAME); >+ } >+ >+ /** >+ * Initial setup is done as first test in collection, both to record its failure, and to allow execution >+ * in the server. >+ */ >+ public void testSetup() { >+ // Table creator shall not be used for this persistence unit. >+ // new AdvancedCustomerTableCreator().replaceTables(getServerSession(PU_NAME)); >+ clearCache(PU_NAME); >+ final EntityManager em = createEntityManager(PU_NAME); >+ try { >+ createCustomer(em); >+ } finally { >+ em.close(); >+ } >+ } >+ >+ /** >+ * Final cleanup is done as last test in collection, both to record its failure, and to allow execution >+ * in the server. >+ */ >+ public void testCleanup() { >+ final EntityManager em = createEntityManager(PU_NAME); >+ try { >+ deleteAllCustomers(em); >+ } finally { >+ em.close(); >+ } >+ } >+ >+ /** >+ * Test JPQL query on {@link RegisteredCustomer} without {@code LEFT JOIN FETCH} of {@link CustomerAddress} >+ * entities. >+ */ >+ public void testJpqlNoFetch() { >+ final EntityManager em = createEntityManager(PU_NAME); >+ try { >+ final Query query = em.createNamedQuery( >+ "RegisteredCustomer.selecByName", >+ RegisteredCustomer.class).setParameter("name", CUSTOMER_NAME); >+ final RegisteredCustomer customer = (RegisteredCustomer) query.getSingleResult(); >+ assertCustomer(customer); >+ } finally { >+ em.close(); >+ } >+ } >+ >+ /** >+ * Test JPQL query on {@link RegisteredCustomer} with {@code LEFT JOIN FETCH} of {@link CustomerAddress} entities. >+ */ >+ public void testJpqlFetch() { >+ final EntityManager em = createEntityManager(PU_NAME); >+ try { >+ final Query query = em.createNamedQuery( >+ "RegisteredCustomer.selecByNameFetch", >+ RegisteredCustomer.class).setParameter("name", CUSTOMER_NAME); >+ final RegisteredCustomer customer = (RegisteredCustomer) query.getSingleResult(); >+ assertCustomer(customer); >+ } finally { >+ em.close(); >+ } >+ } >+ >+ /** >+ * Test criteria query on {@link RegisteredCustomer} without {@code LEFT JOIN FETCH} of {@link CustomerAddress} >+ * entities. >+ */ >+ public void testCriteriaNoFetch() { >+ final EntityManager em = createEntityManager(PU_NAME); >+ try { >+ final CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); >+ final CriteriaQuery<RegisteredCustomer> criteriaQuery >+ = criteriaBuilder.createQuery(RegisteredCustomer.class); >+ final Root<RegisteredCustomer> from = criteriaQuery.from(RegisteredCustomer.class); >+ >+ criteriaQuery.where(criteriaBuilder.equal(from.get("name"), CUSTOMER_NAME)); >+ criteriaQuery.distinct(true); >+ >+ final TypedQuery<RegisteredCustomer> query = em.createQuery(criteriaQuery); >+ final RegisteredCustomer customer = query.getSingleResult(); >+ assertCustomer(customer); >+ } finally { >+ em.close(); >+ } >+ } >+ >+ /** >+ * Test criteria query on {@link RegisteredCustomer} with {@code LEFT JOIN FETCH} of {@link CustomerAddress} >+ * entities. >+ */ >+ public void testCriteriaFetch() { >+ final EntityManager em = createEntityManager(PU_NAME); >+ try { >+ final CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); >+ final CriteriaQuery<RegisteredCustomer> criteriaQuery >+ = criteriaBuilder.createQuery(RegisteredCustomer.class); >+ final Root<RegisteredCustomer> from = criteriaQuery.from(RegisteredCustomer.class); >+ >+ from.fetch("billingAddress", JoinType.LEFT); >+ from.fetch("deliveryAddress", JoinType.LEFT); >+ >+ criteriaQuery.where(criteriaBuilder.equal(from.get("name"), CUSTOMER_NAME)); >+ criteriaQuery.distinct(true); >+ >+ final TypedQuery<RegisteredCustomer> query = em.createQuery(criteriaQuery); >+ final RegisteredCustomer customer = query.getSingleResult(); >+ assertCustomer(customer); >+ } finally { >+ em.close(); >+ } >+ } >+ >+} >-- >1.8.5.2 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 395738
:
224270
|
224285
|
248984
|
248985
|
249144
|
249169