OPENJPA-755 Update to SingleFieldManager to permit detached related entities on a merge with cascade persist.

cosmatic changes only - removed tabs.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@712817 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Catalina Wei 2008-11-10 19:55:00 +00:00
parent e11d0f7e12
commit 5550d8dbb5
5 changed files with 92 additions and 92 deletions

View File

@ -744,7 +744,7 @@ class SingleFieldManager
return;
OpenJPAStateManager sm;
if (vmd.getCascadePersist() == ValueMetaData.CASCADE_NONE) {
if (!_broker.isDetachedNew() && _broker.isDetached(obj))
return; // allow but ignore
@ -755,7 +755,7 @@ class SingleFieldManager
_loc.get("cant-cascade-persist", vmd))
.setFailedObject(obj);
} else {
if (vmd.getCascadePersist() == ValueMetaData.CASCADE_IMMEDIATE) {
if (vmd.getCascadePersist() == ValueMetaData.CASCADE_IMMEDIATE) {
if (!_broker.isDetachedNew() && _broker.isDetached(obj))
return; // allow but ignore
}

View File

@ -27,18 +27,18 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
public class TestDetachedEntityCascadePersist extends SingleEMFTestCase {
public void setUp() {
public void setUp() {
setUp(
CLEAR_TABLES,
DMCustomer.class,
DMItem.class,
DMCustomerInventory.class
);
CLEAR_TABLES,
DMCustomer.class,
DMItem.class,
DMCustomerInventory.class
);
}
public void testDetachedEntityCascadePersist() {
// Persist an item for finding later
EntityManager em = emf.createEntityManager();
// Persist an item for finding later
EntityManager em = emf.createEntityManager();
DMItem item = new DMItem();
item.setName("openjpa");
item.setPrice(0.0);
@ -51,7 +51,7 @@ public class TestDetachedEntityCascadePersist extends SingleEMFTestCase {
em.persist(customer);
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
DMItem itemDetached = em.find(DMItem.class, item.getId());
em.close();

View File

@ -29,8 +29,8 @@ import javax.persistence.OneToMany;
@Entity
public class DMCustomer {
private static long idCounter = System.currentTimeMillis();
private static long idCounter = System.currentTimeMillis();
@Id private long id = idCounter++;
private String firstName;
private String lastName;
@ -38,40 +38,40 @@ public class DMCustomer {
@OneToMany(mappedBy="customer",
fetch=FetchType.EAGER,
cascade=CascadeType.ALL)
private List<DMCustomerInventory> customerInventories = new ArrayList<DMCustomerInventory>();
private List<DMCustomerInventory> customerInventories = new ArrayList<DMCustomerInventory>();
public DMCustomer() {
}
public long getId() {
return id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public void setId(long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public List<DMCustomerInventory> getCustomerInventories() {
return customerInventories;
}
public List<DMCustomerInventory> getCustomerInventories() {
return customerInventories;
}
public void setCustomerInventories(List<DMCustomerInventory> customerInventories) {
this.customerInventories = customerInventories;
}
public void setCustomerInventories(List<DMCustomerInventory> customerInventories) {
this.customerInventories = customerInventories;
}
}

View File

@ -26,50 +26,50 @@ import javax.persistence.ManyToOne;
@Entity
public class DMCustomerInventory {
private static long idCounter = System.currentTimeMillis();
private static long idCounter = System.currentTimeMillis();
@Id private long id = idCounter++;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "CI_ITEMID")
private DMItem item;
private int quantity;
@ManyToOne(cascade=CascadeType.MERGE)
@JoinColumn(name="CI_CUSTOMERID")
private DMCustomer customer;
public DMCustomerInventory() {
}
public long getId() {
return id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public void setId(long id) {
this.id = id;
}
public DMItem getItem() {
return item;
}
public DMItem getItem() {
return item;
}
public void setItem(DMItem item) {
this.item = item;
}
public void setItem(DMItem item) {
this.item = item;
}
public int getQuantity() {
return quantity;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public DMCustomer getCustomer() {
return customer;
}
public DMCustomer getCustomer() {
return customer;
}
public void setCustomer(DMCustomer customer) {
this.customer = customer;
}
public void setCustomer(DMCustomer customer) {
this.customer = customer;
}
}

View File

@ -23,29 +23,29 @@ import javax.persistence.Id;
@Entity
public class DMItem {
private static long idCounter = System.currentTimeMillis();
@Id private long id = idCounter++;
private static long idCounter = System.currentTimeMillis();
@Id private long id = idCounter++;
private String name;
private double price;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
private String name;
private double price;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}