eclipselink without persistence.xml

谁说胖子不能爱 提交于 2019-12-11 03:55:48

问题


I'm not a big fan of XML files. Therefore I'm wondering if there is a way to use eclipselink without its persistence.xml configuration file. Why?

Because I want to manage different databases dynamically. It would be much easier to do it without the XML file.

I'm surprised that I couldn't find anything on the web for now.


回答1:


Not really, but you could create an EclipseLink ServerSession directly and wrap it with an EntityManagerFactoryImpl, but I would not suggest it.

You would be better off creating a persistence.xml. You can still do dynamic databases, you just need to pass a properties file to createEntityManagerFactory(Map) that include your database info.




回答2:


Though it is not an direct answer to your question, this will help for the second part of your question. For managin multiple database connections, you can define multiple server sessions in sessions.xml and access those where you want.

you may use follwoing lines for accessing particular session

ServerSession aSession =   = (ServerSession) SessionManager.getManager().getSession("session_2");


来源:https://stackoverflow.com/questions/9801516/eclipselink-without-persistence-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!