use of EntityManagerFactory causing duplicate primary key exceptions

Posted by bradd on Stack Overflow See other posts from Stack Overflow or by bradd
Published on 2010-03-09T00:48:46Z Indexed on 2010/03/09 0:51 UTC
Read the original article Hit count: 549

Hey guys, my goal is create an EntityManager using properties dependent on which database is in use. I've seen something like this done in all my Google searches(I made the code more basic for the purpose of this question):

@PersistenceUnit
private EntityManagerFactory emf; 
private EntityManager em;
private Properties props;

@PostConstruct
public void createEntityManager(){

//if oracle set oracle properties else set postgres properties

emf = Persistence.createEntityManagerFactory("app-x");
em = emf.createEntityManager(props);
}

This works and I can load Oracle or Postgres properties successfully and I can Select from either database. HOWEVER, I am running into issues when doing INSERT statements. Whenever an INSERT is done I get a duplicate primary key exception.. every time! Can anyone shed some light on why this may be happening? Thanks -Brad

© Stack Overflow or respective owner

Related posts about java-ee

Related posts about persistence-unit