mirror of
https://github.com/apache/openjpa.git
synced 2025-02-07 18:49:44 +00:00
OPENJPA-1174: default fetch type for ManyToOne and OneToOne is eager.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@807602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
049c91707b
commit
9a4406038e
@ -34,6 +34,9 @@ public class Security {
|
|||||||
@JoinColumn(name="COUNTRY_ID")
|
@JoinColumn(name="COUNTRY_ID")
|
||||||
private Country country;
|
private Country country;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
private Country countryEager;
|
||||||
|
|
||||||
public Security() {
|
public Security() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -56,6 +59,14 @@ public class Security {
|
|||||||
this.country = c;
|
this.country = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Country getCountryEager() {
|
||||||
|
return countryEager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCountryEager(Country c) {
|
||||||
|
this.countryEager = c;
|
||||||
|
}
|
||||||
|
|
||||||
public Embed getSymbol() {
|
public Embed getSymbol() {
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ public class Security1 {
|
|||||||
|
|
||||||
private Country1 country;
|
private Country1 country;
|
||||||
|
|
||||||
|
private Country1 countryEager;
|
||||||
|
|
||||||
public Security1() {
|
public Security1() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -48,6 +50,14 @@ public class Security1 {
|
|||||||
this.country = c;
|
this.country = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Country1 getCountryEager() {
|
||||||
|
return countryEager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCountryEager(Country1 c) {
|
||||||
|
this.countryEager = c;
|
||||||
|
}
|
||||||
|
|
||||||
public Embed getSymbol() {
|
public Embed getSymbol() {
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,45 @@ public class TestXMLPersistenceMetaDataParser extends SQLListenerTestCase {
|
|||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testManyToOneEagerFetch() {
|
||||||
|
// initialize objects
|
||||||
|
EntityManager em = emf.createEntityManager();
|
||||||
|
|
||||||
|
long aI_sid = 148007245;
|
||||||
|
long aUS_sid = 2;
|
||||||
|
|
||||||
|
Security1 aI_security = new Security1(aI_sid, new Embed("XYZ"));
|
||||||
|
Country1 aUS_country = new Country1(aUS_sid, "USA");
|
||||||
|
aI_security.setCountry1(aUS_country);
|
||||||
|
aI_security.setCountryEager(aUS_country);
|
||||||
|
|
||||||
|
Security aI_securityAnn = new Security(aI_sid, new Embed("XYZ"));
|
||||||
|
Country aUS_countryAnn = new Country(aUS_sid, "USA");
|
||||||
|
aI_securityAnn.setCountry(aUS_countryAnn);
|
||||||
|
aI_securityAnn.setCountryEager(aUS_countryAnn);
|
||||||
|
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.persist(aI_security);
|
||||||
|
em.persist(aUS_country);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.clear();
|
||||||
|
|
||||||
|
aI_security = em.find(Security1.class, aI_sid);
|
||||||
|
em.clear();
|
||||||
|
Country1 countryEager = aI_security.getCountryEager();
|
||||||
|
assertNotNull(countryEager);
|
||||||
|
|
||||||
|
aI_securityAnn = em.find(Security.class, aI_sid);
|
||||||
|
em.clear();
|
||||||
|
Country countryEagerAnn = aI_securityAnn.getCountryEager();
|
||||||
|
assertNotNull(countryEagerAnn);
|
||||||
|
|
||||||
|
// Close
|
||||||
|
em.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void printArrayList(ArrayList aList) {
|
private void printArrayList(ArrayList aList) {
|
||||||
Iterator itr = aList.iterator();
|
Iterator itr = aList.iterator();
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
<many-to-one name="country" optional="false" fetch="LAZY">
|
<many-to-one name="country" optional="false" fetch="LAZY">
|
||||||
<join-column name="COUNTRY_ID" />
|
<join-column name="COUNTRY_ID" />
|
||||||
</many-to-one>
|
</many-to-one>
|
||||||
|
<many-to-one name="countryEager">
|
||||||
|
</many-to-one>
|
||||||
<embedded name="symbol" />
|
<embedded name="symbol" />
|
||||||
</attributes>
|
</attributes>
|
||||||
</entity>
|
</entity>
|
||||||
|
@ -1425,7 +1425,7 @@ public class XMLPersistenceMetaDataParser
|
|||||||
protected void parseOneToOne(FieldMetaData fmd, Attributes attrs)
|
protected void parseOneToOne(FieldMetaData fmd, Attributes attrs)
|
||||||
throws SAXException {
|
throws SAXException {
|
||||||
String val = attrs.getValue("fetch");
|
String val = attrs.getValue("fetch");
|
||||||
if (val != null && "EAGER".equals(val)) {
|
if (val == null || "EAGER".equals(val)) {
|
||||||
fmd.setInDefaultFetchGroup(true);
|
fmd.setInDefaultFetchGroup(true);
|
||||||
}
|
}
|
||||||
val = attrs.getValue("target-entity");
|
val = attrs.getValue("target-entity");
|
||||||
@ -1444,7 +1444,7 @@ public class XMLPersistenceMetaDataParser
|
|||||||
protected void parseManyToOne(FieldMetaData fmd, Attributes attrs)
|
protected void parseManyToOne(FieldMetaData fmd, Attributes attrs)
|
||||||
throws SAXException {
|
throws SAXException {
|
||||||
String val = attrs.getValue("fetch");
|
String val = attrs.getValue("fetch");
|
||||||
if (val != null && "EAGER".equals(val)) {
|
if (val == null || "EAGER".equals(val)) {
|
||||||
fmd.setInDefaultFetchGroup(true);
|
fmd.setInDefaultFetchGroup(true);
|
||||||
}
|
}
|
||||||
val = attrs.getValue("target-entity");
|
val = attrs.getValue("target-entity");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user