OPENJPA-782: fix default element collection table name to comply with the Spec

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@886883 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2009-12-03 19:11:45 +00:00
parent 123e0b6120
commit f697798fd8
7 changed files with 117 additions and 4 deletions

View File

@ -135,8 +135,12 @@ public class PersistenceMappingDefaults
ClassMapping clm = fm.getDefiningMapping();
Table table = getTable(clm);
String name = table.getName();
String name = null;
if (fm.isElementCollection())
name = clm.getTypeAlias();
else
name = table.getName();
// if this is an assocation table, spec says to suffix with table of
// the related type. spec doesn't cover other cases; we're going to
// suffix with the field name

View File

@ -20,6 +20,7 @@ package org.apache.openjpa.persistence.criteria;
import java.util.Set;
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@ -37,6 +38,7 @@ public class Person {
private String name;
@ElementCollection
@CollectionTable(name="CR_PSN_NICKNAMES")
private Set<String> nickNames;
protected Person() {

View File

@ -0,0 +1,72 @@
/*
* 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.util.HashSet;
import java.util.Set;
import javax.persistence.*;
@Entity
@Table(name = "A_EMB")
public class A implements java.io.Serializable {
@Id
protected String id;
String name;
int value;
@ElementCollection
protected Set<Embed> embeds = new HashSet();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public Set<Embed> getEmbeds() {
return embeds;
}
public void setEmbeds(Set<Embed> embeds) {
this.embeds = embeds;
}
}

View File

@ -27,6 +27,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -99,7 +100,7 @@ public class TestEmbeddable extends SQLListenerTestCase {
EntityA_Embed_MappedToOneCascadeDelete.class, EntityB2.class,
Book.class, Listing.class, Seller.class,
EntityA_Embed_Coll_Map.class, Embed_Coll_Map.class,
EntityA_Embed_Complex.class, CLEAR_TABLES);
EntityA_Embed_Complex.class, A.class, CLEAR_TABLES);
sql.clear();
DBDictionary dict = ((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance();
if (dict.getClass().getName().indexOf("oracle") != -1) {
@ -2956,5 +2957,36 @@ public class TestEmbeddable extends SQLListenerTestCase {
assertEquals(6, findA.getEmbeds().size());
em.close();
}
/*
* test the default name for element collection table
*/
public void testDefaultNameForElementCollection() {
getLog().trace("testDefaultNameForElementCollection() - entered");
EntityManager em = emf.createEntityManager();
EntityTransaction tran = em.getTransaction();
tran.begin();
A a = new A();
a.setId("1");
Embed embed = new Embed();
embed.setIntVal1(1);
embed.setIntVal2(2);
embed.setIntVal3(3);
Set embeds = new HashSet();
embeds.add(embed);
a.setEmbeds(embeds);
tran.commit();
em.close();
boolean found = false;
for (String sqlStr : sql) {
if (sqlStr.toUpperCase().indexOf("A_EMBEDS") != -1) {
found = true;
break;
}
}
assertTrue(found);
}
}

View File

@ -61,6 +61,7 @@ public class Employee {
ContactInfo contactInfo;
@ElementCollection
@CollectionTable(name="EMP_ATTROVER_jobInfos")
@AssociationOverride (
name="value.pm",
joinColumns=@JoinColumn(name="PROGRAM_MGR")

View File

@ -20,7 +20,7 @@ package org.apache.openjpa.persistence.embed.attrOverrides;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -39,6 +39,7 @@ public class Person {
protected List<Address> residences = new ArrayList<Address>();
@ElementCollection
@CollectionTable(name="PSN_nickNames")
@OrderBy("DESC")
private List<String> nickNames = new ArrayList<String>();

View File

@ -36,6 +36,7 @@ public class PropertyRecord {
@AttributeOverride(name="value.tax", column=@Column(name="ASSESSMENT"))
})
@ElementCollection
@CollectionTable(name="PROPREC_ATTROVER_parcels")
Map<Address, PropertyInfo> parcels = new HashMap<Address, PropertyInfo>();
@Column(length = 10)