The situation is following. I have a small test example with 4 classes:
@Entity (name = "EntityA")
@Table (name = "TBL_A")
public class EntityA implements Serializable
{
private int id;
private String f1;
public EntityA()
{
}
public EntityA(int id, String f1)
{
this.f1 = f1;
this.id = id;
}
@Id
@Column (name = "ID")
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
@Basic
@Column (name = "F1")
public String getF1()
{
return f1;
}
public void setF1(String f1)
{
this.f1 = f1;
}
}
...
@Remote
public interface SFSBA
{
public void updateEntities(List<EntityA> entities);
}
...
@Stateless
public class SFSBAImpl implements SFSBA
{
@PersistenceContext
private EntityManager em;
public void updateEntities(List<EntityA> entities)
{
for(EntityA e : entities)
em.merge(e);
}
}
...
public class Test1
{
@Test
public void test1() throws NamingException
{
List<EntityA> entities = new ArrayList<EntityA>();
entities.add(new EntityA(1, "a"));
entities.add(new EntityA(1, "a"));
SFSBA bean = (SFSBA)(new InitialContext()).lookup(SFSBA.class.getCanonicalName());
bean.updateEntities(entities);
}
}
As result I get an exception:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 9.1 (Build b32)): oracle.t
oplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00001...
Error Code: 1
Call:INSERT INTO TBL_A (ID, F1) VALUES (?, ?)
bind => [1, a]
So as you see I try to call merge twice on the same new entity.
The same situation is with persist method also.
As I understand the spec (#3.2.4.1) there is nothing illegal with this example.
Of course there is a workaround with this issue but...
What are your thoughts about this?
[Message sent by forum member 'hazurek' (hazurek)]
http://forums.java.net/jive/thread.jspa?messageID=208084