Я использую эти зависимости: < /p>
Код: Выделить всё
org.eclipse.persistence
eclipselink
2.5.1
org.eclipse.persistence
javax.persistence
2.1.0-RC1
< /code>
Должен ли я добавить sth в свой файл stristence.xml? Если да, то, что я должен добавить? public void writeAllJobs(List jobs) {
final EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
int counter= 0;
for (final Job j : jobs) {
if (counter++ >= 100) {
em.getTransaction().commit();
em.getTransaction().begin();
counter = 0;
}
final Job job = new Job();
job.setJobkey(j.getJobkey());
job.setDescription(b.getDescription());
em.persist(job);
}
em.getTransaction().commit();
em.close();
}
Код: Выделить всё
public void writeAllJobs(List jobs) throws SQLException {
final EntityManager em = factory.createEntityManager();
final java.sql.Connection connection = em.unwrap(java.sql.Connection.class);
final String compiledQuery = "INSERT INTO JOB(JOBKEY ,DESCRIPTION)" + " VALUES" + "(?, ?)";
final PreparedStatement preparedStatement = connection.prepareStatement(compiledQuery);
for (final Job j : jobs) {
preparedStatement.setInt(1, j.getJobkey());
preparedStatement.setString(2, j.getDescription());
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
connection.close();
}
< /code>
Тогда я получаю: java.lang.nullpointerexception < /code> < /p>
------------------------------ РЕДАКТИЯ 2 ------------------------------------------- < /strong> < /p>
Я получил NPE в строке
< /p>
.final java.sql.Connection connection = em.unwrap(java.sql.Connection.class);Но как мне решить эту проблему?
Подробнее здесь: https://stackoverflow.com/questions/709 ... clipselink