@Before public void setUp() { jdbcTemplate = new JdbcTemplate(dataSource); // Create an agent for testing EntityManager entityManager = emf.createEntityManager(); EntityTransaction tx = entityManager.getTransaction(); tx.begin(); Agent agent = new Agent("An agent"); entityManager.persist(agent); agentId = agent.getId(); tx.commit(); entityManager.close(); }
@Test public void singleEntity() { EntityManager entityManager = emf.createEntityManager(); EntityTransaction tx = entityManager.getTransaction(); tx.begin(); printAgent("at start"); Agent agent = (Agent) entityManager.find(Agent.class, agentId); agent.setDescription("A"); printAgent("after setting A"); agent.setDescription("B"); printAgent("after setting B"); tx.commit(); printAgent("after commit"); entityManager.close(); }