OPENJPA-2229: Honor JoinColumn.name when mapping a uni-directional OneToOne that is in a SecondaryTable.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1369042 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2012-08-03 15:33:00 +00:00
parent bcda87c67b
commit a55000a4be
4 changed files with 144 additions and 1 deletions

View File

@ -1095,7 +1095,9 @@ public class MappingRepository extends MetaDataRepository {
field.getAssociationType() == FieldMetaData.ONE_TO_ONE &&
hasJoinTable(field) &&
!isBidirectional(field)) {
field.getValueMapping().getValueInfo().setColumns(field.getElementMapping().getValueInfo().getColumns());
List<Column> cols = field.getElementMapping().getValueInfo().getColumns();
if (cols != null && cols.size() > 0)
field.getValueMapping().getValueInfo().setColumns(cols);
return true;
}
return false;

View File

@ -0,0 +1,56 @@
/*
* 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.
*/
/*
* 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.meta;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Version;
@Entity
public class PChild {
@Id
@GeneratedValue
int idChild;
@Version
int version;
@Basic
String basic;
}

View File

@ -0,0 +1,44 @@
/*
* 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.meta;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
@Entity
@SecondaryTable(name = "ParentSecondaryTable", pkJoinColumns =
{ @PrimaryKeyJoinColumn(name = "idParent", referencedColumnName = "idParent") })
public class Parent {
@Id
@GeneratedValue
int idParent;
String child_ref;
@OneToOne
@JoinColumn(name = "CHILD_REF", table = "ParentSecondaryTable", referencedColumnName = "idChild")
PChild child;
}

View File

@ -0,0 +1,41 @@
/*
* 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.meta;
import org.apache.openjpa.jdbc.meta.FieldMapping;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
public class TestSecondaryTable extends SingleEMFTestCase {
public void setUp() {
setUp(Parent.class, PChild.class
// Hard code to 2.0 p.xml value. If the p.xml is 1.0, this value will be changed to false, and the test
// won't fail.
, "openjpa.Compatibility", "NonDefaultMappingAllowed=true");
}
/**
* Added for OPENJPA-22229.
*/
public void testMappingInfo() {
FieldMapping fm = getMapping(Parent.class).getFieldMapping("child");
assertNotNull(fm);
assertEquals("CHILD_REF", fm.getColumns()[0].getIdentifier().getName());
}
}