mirror of https://github.com/apache/openjpa.git
OPENJPA-509 Fix & Test for insertion of MappedSuperClass-Entity-Embedded domain model insertion failure.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@618794 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c767561f9d
commit
024faa31d7
|
@ -165,7 +165,8 @@ public class EmbedFieldStrategy
|
|||
FieldMapping[] fields = field.getEmbeddedMapping().getFieldMappings();
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
if (!Boolean.TRUE.equals(fields[i].isCustomInsert(em, store)))
|
||||
fields[i].insert(em, store, rm);
|
||||
if (!fields[i].isPrimaryKey())
|
||||
fields[i].insert(em, store, rm);
|
||||
|
||||
if (field.getColumnIO().isInsertable(0, true))
|
||||
setNullIndicatorColumn(sm, row);
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 javax.persistence.*;
|
||||
|
||||
/**
|
||||
* An entity that extends a MappedSuperClass and embeds an entity.
|
||||
*
|
||||
* @author Pinaki Poddar
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class Address extends BaseEntity {
|
||||
protected String streetAddress, city, state;
|
||||
|
||||
Geocode geocode;
|
||||
|
||||
@Embedded
|
||||
public Geocode getGeocode() {
|
||||
return geocode;
|
||||
}
|
||||
|
||||
public void setGeocode(Geocode geocode) {
|
||||
this.geocode = geocode;
|
||||
}
|
||||
|
||||
public String getStreetAddress() {
|
||||
return streetAddress;
|
||||
}
|
||||
|
||||
public void setStreetAddress(String streetAddress) {
|
||||
this.streetAddress = streetAddress;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
protected Integer zip;
|
||||
|
||||
public Integer getZip() {
|
||||
return zip;
|
||||
}
|
||||
|
||||
public void setZip(Integer zip) {
|
||||
this.zip = zip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 javax.persistence.*;
|
||||
|
||||
/**
|
||||
* Mapped Super Class using auto-generated identity.
|
||||
*
|
||||
* @author Pinaki Poddar
|
||||
*
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class BaseEntity {
|
||||
protected Long id;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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 javax.persistence.*;
|
||||
|
||||
/**
|
||||
* An embedded entity.
|
||||
*
|
||||
* @author Pinaki Poddar
|
||||
*
|
||||
*/
|
||||
@Embeddable
|
||||
public class Geocode extends BaseEntity {
|
||||
float latitude, longtitude;
|
||||
|
||||
public float getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(float latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public float getLongtitude() {
|
||||
return longtitude;
|
||||
}
|
||||
|
||||
public void setLongtitude(float longtitude) {
|
||||
this.longtitude = longtitude;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 javax.persistence.EntityManager;
|
||||
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
|
||||
public class TestEmbedded extends SingleEMFTestCase {
|
||||
public void setUp() {
|
||||
super.setUp(BaseEntity.class, Address.class, Geocode.class,
|
||||
CLEAR_TABLES);
|
||||
}
|
||||
|
||||
public void testInsertEmbedded() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
Address a = new Address();
|
||||
a.setStreetAddress("123 Main St");
|
||||
a.setCity("Chicago");
|
||||
a.setState("IL");
|
||||
a.setZip(60606);
|
||||
Geocode g = new Geocode();
|
||||
g.setLatitude(1.0f);
|
||||
g.setLongtitude(2.0f);
|
||||
a.setGeocode(g);
|
||||
em.persist(a);
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue