Details
Description
Maybe you know, one of the entity implementation is composite of a hash set, which stores key-value pairs.
It's a common design of Entity Bean in EJB2.x ages. Does any one use it in OpenJPA? I am using it right now, and encounter an issue in entity cascade manipulate. Here is the issue description.
Base.java : the super class of entities.
protected final Object getAttributeValue(String attributeName)
protected final void setAttributeValue(String attributeName, Object value)
{ _values.put(attributeName, value); }// To hold the
{attributeName, value} pair of the value object.
private HashMap<String, Object> _values = new HashMap<String, Object>();
C.java extends Base.java : Entity C has a set of Entity D.
public void setDs(Set<D> ds)
@OneToMany(mappedBy = "c", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
public Set<D> getDs()
D.java extends Base.java as well.
The relationship between C and D is one-to-many. I use following code to reproduce the issue.
C c = em.find(C.class, 1);
logger.debug(c.getDs().size());
D d = new D();
d.setC(c);
c.getDs().add(d);
em.merge(c);
After commit the transaction, you will find the new D instance was not inserted into the database(there is no insert sql log as well). After you add, em.persist(c). That new instance will be added!
Meanwhile, I wrote a couple of classes, which do not use a HashSet. I got the expected result after merge is done.