| createnativequery [message #1864520] |
Thu, 21 March 2024 06:15  |
Eclipse User |
|
|
|
In our JPA implementation using eclipselink we are having oracleucp as datasource provider and we use the following the convention to invoke plsql pacakage calls in the database
try (CallableStatement cs = getThreadLocalEntityManager().getEntityManager().unwrap(Connection.class).
prepareCall(functionCall)
...
...
cs.execute()
what we noticed was the above lines of code execution was behaving with autocommit as true and any insert/update dml operation in package was getting auto committed as a part of cs.execute command.
But if the above plsql package call was preceeded with the createnativequery call for example
em.createNativeQuery("select 1 from dual").getSingleResult();
and then if we have the plsql package call after that we noticed was
1) the autocommit behavior during cs.execute was not happening
2) the subsequent createnative select calls to fetch records inserted via plsql package was fetching the records
the above 2 points is what we need as a part of our application requirements,
Just wanted to confirm the above and any other side effects of this behavior
|
|
|
|
| Re: createnativequery [message #1864565 is a reply to message #1864562] |
Tue, 26 March 2024 00:45  |
Eclipse User |
|
|
|
Thanks Chris, our product has a long history wherein
1) It was inclient server architecture and evolved over a period of 15-20 years with lot of db package calls. and each logged in user having a dedicated connection available wherein there can be multiple package calls on various app actions (button clicls, checkbox actions etc) and uses had the luxury of doing a final commit or cancel at the end.
2) Now we are in process of refactoring to the cloud architecture and one thought is to reuse the packages as much as possible with minimal changes as it may take year(s) to build/test. So found out a feature in eclipse link entity manager (https://eclipse.dev/eclipselink/documentation/2.5/jpa/extensions/p_jdbc_exclusiveconnection_mode.htm#:~:text=EclipseLink%20keeps%20the%20connection%20exclusive%20for%20the%20lifetime%20of%20the,read%20through%20the%20exclusive%20connection.) which kind of mimicked the dedicated db connection behavior and trying to execute the package calls . So the idea here is to have ems mapped to each user based on session cookie with code like below and have package calls executed under the em context
private static Map<String,EntityManager> emMap=new HashMap<String,EntityManager>();
..
..
..
Map<String, String> propertiesMap=new HashMap<>();
private String fetchJessionCookie() {
Map headerCookies=restFlowContext.getHeaders().getCookies();
return ((Cookie)headerCookies.get("JSESSIONID")).getValue();
}
propertiesMap.put(PersistenceUnitProperties.EXCLUSIVE_CONNECTION_MODE, "Always");
em =emf.createEntityManager(propertiesMap);
emMap.put(fetchJessionCookie(), em );
|
|
|
Powered by
FUDForum. Page generated in 0.03620 seconds