Shailesh Kini.
Tony McClay<br />Architect / Developer, SOA and Jave Enterprise Edition 1-5<br />---------------------------------------------------------------------- <br />Sun Certified Enterprise Architect, Enterprise Edition 5 (Step 1 of 3)<br />Sun Certified Web Component Developer, Enterprise Edition 4<br />Sun Certified Business Component Developer Enterprise Edition 5<br />Sun Certified Programmer , Standard Edition 5.0
Shailesh Kini.
Originally posted by Sean Brown:
I override my properties too, but I have to override the entire data source at runtime. (The SQL database name is associated to the client's account)
I use Toplink Essentials and MySQL.
But.. Toplink caches the JDBC Connection, so if I create an entity manager a second time, while it says it's connected to the second database, it actually pulls entities from the conenction of the first entity manager created (per VM instance, of course).
If anyone knows how to stop this behavior or if another persistence provider (Hibernate, OpenJPA?) doesn't cache the connection, We would _love_ to hear about it.
Originally posted by Sean Brown:
No, I've tried it. Toplink caches the JDBC Connection per Persistence Unit, so it is impossible to override the property and it have any effect. This may not be the case with another JPA Implementation, I don't know (I haven't been able to get most of them working).
I made a debug script which dumps the entire VM (especially toplink) and I can see the property being overridden, but I also see the Connection object has the same Identity as for the entity manager with the property set to a different connection url.
Originally posted by Sean Brown:
A: I was creating an entirely new factory for each EM I made, so I could indeed override the properties for each EM.
B: I fixed the problem by switching back to hibernate and fixing the other bug that was giving me beef (Hibernate out-of-the-box has problems with optional entity relationships which don't cascade deletes).
Originally posted by Sean Brown:
I *am* keeping the entity manager a long time. If it allows (ie. the connection doesn't time out?), for the life of the application; not for each transaction.
The only thing that kept the leeches off of me was this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|