Hi,

I am trying to persist a data by using EntityManager.persist method. I am using EJB 3.0 Stateless Session Facade Bean and its transaction is Container-Managed. (CMP)
After persist operation, within the same ejb method, I am trying to update the data by using a JDBC "Update" query. But the problem is that the data is not updated. The transaction is not committed before the execution of the ejb method finishes, I know that. But even if that's the case, the data should be updated, as I know.

The code is given below:

Java Code:
public void ejbMethod() {
	Dummy t = new Dummy();
	t.setCreatedBy("H");
	t.setId(1000L);
	em.persist(t);
	
	StringBuffer sqlClause = new StringBuffer("");            
	sqlClause = sqlClause.append("UPDATE DUMMY SET CREATED_BY = 'K' WHERE ID = 1000");
	
	try {
		Connection conn = ds.getConnection();
		PreparedStatement statement = conn.prepareStatement(sqlClause.toString());
		statement.executeUpdate();
		conn.close();
	} catch (SQLException e) {
		log.error(e);
	}
}
So when I check the data from the database, the created_by column remains as "H", it is not updated. But when I try to update the data by using the pojo and EntityManager.merge method with the given code below:

Java Code:
public void ejbMethod() {
	Dummy t = new Dummy();
	t.setCreatedBy("H");
	t.setId(1000L);
	t = (Dummy)em.persist(t);
	
	t.setCreatedBy("K");
	em.merge(t);
}
The data is updated in the database in the same transaction of persisting.

But I need to use the JDBC query within the ejbMethod.

I have tried "conn.setTransactionIsolation(Connection.TRANSACTI ON_READ_UNCOMMITTED);" , but it did not work.

I think the transaction that the jdbc connection uses is different than the transaction that the persist operation uses.

How will I resolve this problem? Is there any setting that I need to configure?

Thanks in advance.