mirror of https://github.com/apache/openjpa.git
OPENJPA-1793 @EmbeddedId class having only one field java.sql.Data. Contributed by Heath Thomann.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@1027632 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e67a8daeb0
commit
29604c1e39
|
@ -310,10 +310,17 @@ public class HandlerFieldStrategy
|
|||
Object val = null;
|
||||
if (cols.length == 1) {
|
||||
col = cols[0];
|
||||
if (fk != null)
|
||||
if (fk != null){
|
||||
col = fk.getColumn(col);
|
||||
val = res.getObject(col, field.getHandler().
|
||||
getResultArgument(field), joins);
|
||||
}
|
||||
|
||||
//OJ-1793: Get the args from the handler and first check to see if the
|
||||
//args are null. If they aren't null then use the first element in the args
|
||||
//array rather than passing into 'getObject' the entire args array. This is
|
||||
//akin to what is done in the 'else if' leg below.
|
||||
Object[] args = (Object[]) field.getHandler().getResultArgument(field);
|
||||
val = res.getObject(col, (args == null) ? null : args[0],
|
||||
joins);
|
||||
} else if (cols.length > 1) {
|
||||
Object[] vals = new Object[cols.length];
|
||||
Object[] args = (Object[]) field.getHandler().
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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.embed;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
/* This test was created to test OJ-1793 */
|
||||
|
||||
@Embeddable
|
||||
public class Embed_Single_Coll {
|
||||
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date date;
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((date == null) ? 0 : date.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Embed_Single_Coll other = (Embed_Single_Coll) obj;
|
||||
if (date == null) {
|
||||
if (other.date != null)
|
||||
return false;
|
||||
} else if (!date.equals(other.date))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.embed;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class EntityA_Embed_Single_Coll implements Serializable {
|
||||
|
||||
@EmbeddedId
|
||||
protected Embed_Single_Coll embed;
|
||||
|
||||
@Column(length = 30)
|
||||
String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Embed_Single_Coll getEmbed() {
|
||||
return embed;
|
||||
}
|
||||
|
||||
public void setEmbed(Embed_Single_Coll embed) {
|
||||
this.embed = embed;
|
||||
}
|
||||
}
|
|
@ -103,7 +103,8 @@ public class TestEmbeddable extends SQLListenerTestCase {
|
|||
Embed_MappedToOne.class, Embed_MappedToOneCascadeDelete.class,
|
||||
EntityA_Embed_MappedToOneCascadeDelete.class, EntityB2.class,
|
||||
Book.class, Listing.class, Seller.class,
|
||||
EntityA_Embed_Coll_Map.class, Embed_Coll_Map.class, EntityA_Embed.class,
|
||||
EntityA_Embed_Coll_Map.class, Embed_Coll_Map.class,
|
||||
EntityA_Embed_Single_Coll.class, Embed_Single_Coll.class, EntityA_Embed.class,
|
||||
EntityA_Embed_Complex.class, A.class, CLEAR_TABLES);
|
||||
sql.clear();
|
||||
DBDictionary dict = ((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance();
|
||||
|
@ -160,6 +161,35 @@ public class TestEmbeddable extends SQLListenerTestCase {
|
|||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for OJ-1793.
|
||||
*/
|
||||
public void testEntityA_Embed_Single_Coll() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
//create an EntityA_Embed_Single_Coll and persist it.
|
||||
EntityA_Embed_Single_Coll eesc = new EntityA_Embed_Single_Coll();
|
||||
Embed_Single_Coll esc = new Embed_Single_Coll();
|
||||
java.sql.Date date = java.sql.Date.valueOf("2010-10-13");
|
||||
esc.setDate(date);
|
||||
eesc.setEmbed(esc);
|
||||
em.getTransaction().begin();
|
||||
em.persist(eesc);
|
||||
em.flush();
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
||||
//Now query the recently created EntityA_Embed_Single_Coll. Without OJ-1793, when you query
|
||||
//the EntityA_Embed_Single_Coll object, the issue of OJ-1793 will occur, regardless of the query
|
||||
//string (even the simplest string will do).
|
||||
em = emf.createEntityManager();
|
||||
Query query1 = em.createQuery("SELECT e FROM EntityA_Embed_Single_Coll e "
|
||||
+ "where e.embed.date = '" + date + "'");
|
||||
eesc = (EntityA_Embed_Single_Coll) query1.getSingleResult();
|
||||
assertEquals(eesc.getEmbed().getDate().toString(), date.toString());
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testEntityA_Embed_Coll_Map() {
|
||||
queryEntityA_Embed_Coll_Map();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue