I am creating a tiny web application which uses JPA to communicate with the database using Hibernate. I have created the java classes from the database table with the MyEclipse 6.5 reverse engineering tool. This works well.
Now I need to be able to support multiple databases, the actual database being determined at runtime. I understand the way to do this is to pass a map of properties to the EntityManagerFactory to get the EntityManager.
Unfortunately the EntityManagerHelper as generated by MyEclipse 6.5 initializes the EntityManager object in the “static {….}” section meaning that it is done at class load time, so it is practically impossible to alter the behaviour by subclassing or creating the EntityManager object “outside” of EntityManagerHelper. This means that I will have to change the generated class itself, and then these changes will be overwritten next time I do a reverse engineer which is not optimal.
I suggest that since everything goes through getEntityManager() anyway, these fields should not be statically initizalied, but checked for null in getEntityManager() and only if null should be initialized to the default. This allow me to load the class, set the EntityManager externally, and then just go ahead. The persistance unit name should then also be externaly accessible .
Can this be changed for MyEclipse 7.0, please?
/Thorbjørn