Author: ppoddar
Date: Tue Jun 26 20:55:03 2012
New Revision: 1354225
URL: http://svn.apache.org/viewvc?rev=1354225&view=rev
Log:
add a test with entity with separate Id class
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/EntityWithIdClass.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestId.java
(with props)
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java?rev=1354225&r1=1354224&r2=1354225&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
Tue Jun 26 20:55:03 2012
@@ -43,7 +43,8 @@ public abstract class CriteriaTest exten
Dependent.class, D.class, Employee.class, Exempt.class,
FemaleUser.class, FrequentFlierPlan.class,
Item.class, LineItem.class, Magazine.class, MaleUser.class,
Manager.class, Movie.class, Order.class,
Person.class, Phone.class, Photo.class, Product.class,
Publisher.class, Request.class, Semester.class,
- Student.class, TransactionHistory.class, Transaction.class,
VideoStore.class, Foo.class, Bar.class};
+ Student.class, TransactionHistory.class, Transaction.class,
VideoStore.class, Foo.class, Bar.class,
+ EntityWithIdClass.class};
protected Class<?>[] getDomainClasses() {
return CLASSES;
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/EntityWithIdClass.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/EntityWithIdClass.java?rev=1354225&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/EntityWithIdClass.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/EntityWithIdClass.java
Tue Jun 26 20:55:03 2012
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openjpa.persistence.criteria;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+
+/**
+ * A persistent class using a {@link TestId separate class} as its primary
identifier.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+@IdClass(TestId.class)
+public class EntityWithIdClass {
+ @Id
+ private String name;
+ @Id
+ private long ssn;
+ public EntityWithIdClass(String name, long ssn) {
+ this.name = name;
+ this.ssn = ssn;
+ }
+
+ public String getName() {
+ return name;
+ }
+ public long getSsn() {
+ return ssn;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/EntityWithIdClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestId.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestId.java?rev=1354225&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestId.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestId.java
Tue Jun 26 20:55:03 2012
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.openjpa.persistence.criteria;
+
+/**
+ * A class is used as an identifier to {@link EntityWithIdClass another
persistent entity}.
+ * <br>
+ * The type and name of the declared fields of this class and the identifier
fields declared
+ * in the persistent entity must be compatiable.
+ * <br>
+ * This class also must implement its <tt>equals()</tt> and
<tt>hashCode()</tt> methods
+ * properly i.e. involving the declared fields. Otherwise a JPA runtime will
not work
+ * properly.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class TestId {
+ String name;
+ long ssn;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 :
name.hashCode());
+ result = prime * result + (int) (ssn ^ (ssn >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ TestId other = (TestId) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (ssn != other.ssn)
+ return false;
+ return true;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestId.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java?rev=1354225&r1=1354224&r2=1354225&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
Tue Jun 26 20:55:03 2012
@@ -950,7 +950,7 @@ public class TestTypesafeCriteria extend
+ "INNER JOIN CR_PHT t2 ON t1.VALUE_ID = t2.id WHERE " +
"((t1.KEY0 = ? OR t1.KEY0 = ? OR t1.KEY0 = ? OR t1.KEY0 = ? OR
t1.KEY0 = ?) "
+ "AND 0 < (SELECT COUNT(*) FROM CR_ITEM_photos WHERE
CR_ITEM_photos.ITEM_ID = t0.id))";
-
+
CriteriaQuery<Customer> q = cb.createQuery(Customer.class);
Root<Item> item = q.from(Item.class);
MapJoin<Item, String, Photo> photo = item.join(Item_.photos);
@@ -1596,5 +1596,13 @@ public class TestTypesafeCriteria extend
assertTrue(result.get(0) instanceof BigDecimal);
}
-
+ public void testIdClass() {
+ String jpql = "select p from EntityWithIdClass p";
+
+ CriteriaQuery<EntityWithIdClass> cq =
cb.createQuery(EntityWithIdClass.class);
+ Root<EntityWithIdClass> c = cq.from(EntityWithIdClass.class);
+ em.createQuery(cq).getResultList();
+
+ assertEquivalence(cq, jpql);
+ }
}