I'm using JPA EntityManager to insert items into a MySQL database, I have code that reads files, collects data, and then adds that data to the appropriate file. What I'm writing is a simplified version of what I'm trying to do, and I appreciate 100% that both makes it harder to understand what I'm actually doing and could conceal the source of the error, so thank you for bearing with me. The object p I use is generated earlier, and is a LinkedHashMap of form
LinkedHashMap<String MyObject>
Where "MyObject" is a class that has several attributes like "name", "weight", "color", and the String is a UUID meant to serve as the primary key.
private final EntityManagerFactory emf = Persistence.createEntityManagerFactory(myUI.PERSISTENCE_UNIT);
private final EntityManager em = emf.createEntityManager();
for (String key : p.keySet()) {
databaseWriter.writeToDatabase(em, key, p.get(key).getName(),
p.get(key).getColor(), p.get(key).getWeight();
}
And the relevent code from "databaseWriter.writeToDatabase" is
public void writeToDatabase (EntityManager em, String id, String name,String Color, String weight) {
em.GetTransaction().begin();
MyObjectTable mt = new MyObjectTable();
mt.setId(id);
mt.setColor(color);
mt.setWeight(weight);
mt.setName(name);
em.persist(mt);
em.getTransaction().commit();
}
I've confirmed I'm generating the objects in the correct form and passing the information to the function correctly, but I'm having the weirdest behavior. Say there are 15 items in "p", It will only add a few of them, and its not consistent about which few it adds, and its not even consistent about how many "a few" is. I'm hoping its because I'm doing something stupid with EntityManager that is apparent here.
If you need more details than this, I'd be happy to provide them, I just can't think what would cause only some objects to be added (and those objects that are added have the correct information), but only a particular few, not the same few on subsequent attempts, and no errors popping up at all.
Edit: The jpa provider I am using is EclipseLink and I have eddited the factory with something I missed
Edit: here is an example an eclipse server log of a piece of data being entered that does not show up in the databse, can anyone glean anything from this?
[EL Finest]: query: 2016-09-14 12:18:23.867--UnitOfWork(1915196068)--Thread(Thread[http-nio-8084-exec-252,5,main])--Execute query InsertObjectQuery(com.myfiles.stuff_the.PartTable[ idPart=99a26bca-d818-4959-a328-75c1f05a1e38 ])
[EL Fine]: sql: 2016-09-14 12:18:23.867--ClientSession(1291663611)--Connection(1232332820)--Thread(Thread[http-nio-8084-exec-252,5,main])--INSERT INTO PartTable (idPart, dateCreated, description, hash, isBasic, lastModified, name, riskGroup, authorId, formatId, nucseqId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [99a26bca-d818-4959-a328-75c1f05a1e38, 2016-09-14 12:18:23.82, , null, 1, 2016-09-14 12:18:23.82, AXL2 mRNA, null, 1, null, d6f807f0-ac91-4421-8ff2-4940706fd5bb]
I have looked through the whole log file, and can't find any errors, there are the correct number of persist() and commit() statements, not really sure what's going on.