Add the ability to inject EntityManagers for a certain persistence unit in Eclipse 4.
First of all you have to get the Gemini JPA and Gemini DBAccess bundles to make this work. A sample target platform for Juno is available here.
The p2 repositories
You can directly inject an EntityManager
via
@Inject
@GeminiPersistenceContext(unitName="puTest")
EntityManager em;
or you can inject an EntityManagerFactory
if you want to have more
control of your EntityManagers
@Inject
@GeminiPersistenceUnit(unitName="puTest")
EntityManager em;
You can even configure your persistence units within the inject annotation.
@Inject
@GeminiPersistenceContext(unitName="puTest", properties = {
@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_DRIVER, value="org.gjt.mm.mysql.Driver"),
@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_URL, value="jdbc:mysql://127.0.0.1/test"),
@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_USER, value="test"),
@GeminiPersistenceProperty(name=PersistenceUnitProperties.JDBC_PASSWORD, value="test"))
})
EntityManager em;
even with the Preference
annotation. If you don't know them take a look here
@Inject
@GeminiPersistenceContext(unitName = "unconfigured2", properties = {
@GeminiPersistenceProperty(name = PersistenceUnitProperties.JDBC_DRIVER, valuePref = @Preference("jdbc_driver")),
@GeminiPersistenceProperty(name = PersistenceUnitProperties.JDBC_URL, valuePref = @Preference("jdbc_url")) })
private EntityManager em;
A complete sample application can be found here. It contains examples for
- Statically injected contexts
- Dynamically injected contextes
- Handling changing preferences with DAOs
This repository contains the work done by Filipp A. and Nepomuk Seiler. See Gemini Forum Post for more information.