Play Framework fails to read db config and to inject JPAApi - java

I'm trying and failing to use play 2.5.
My Controller:
public class HomeController extends Controller {
private JPAApi db;
#Inject
public HomeController(JPAApi api) {
this.db = api;
}
public Result index(String name) {
return ok(views.html.index.render("hello", name, Collections.singletonList("world")));
}
}
My conf\META-INF\persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="readwritePU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>ReadWriteDS</non-jta-data-source>
<properties>
<property name="hibernate.connection.isolation" value="1" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.use_query_cache" value="false" />
</properties>
</persistence-unit>
</persistence>
My conf\application.conf
jpa.default=readwritePU
db {
#pool = "hikaricp"
default.driver = org.postgresql.Driver
default.url = "jdbc:postgresql://127.0.0.1:5432/mydbname"
default.username = "postgres"
default.password = "123456"
#default = "default"
default.jndiName=ReadWriteDS
}
The error without and with pool config key enabled in application.conf above:
No configuration setting found for key 'pool'
Error in custom provider, com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'pool'
while locating play.api.db.DBApiProvider
while locating play.api.db.DBApi
for field at play.api.db.NamedDatabaseProvider.dbApi(DBModule.scala:80)
while locating play.api.db.NamedDatabaseProvider
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$namedDatabaseBindings$1.apply(DBModule.scala:34):
Binding(interface play.api.db.Database qualified with QualifierInstance(#play.db.NamedDatabase(value=default)) to ProviderTarget(play.api.db.NamedDatabaseProvider#7af4d3bc)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'pool'
pool has type STRING rather than OBJECT
Error in custom provider, com.typesafe.config.ConfigException$WrongType: application.conf # file:/E:/workspace2/coup/target/scala-2.11/classes/application.conf: 344: pool has type STRING rather than OBJECT
while locating play.api.db.DBApiProvider
while locating play.api.db.DBApi
for parameter 0 at play.db.DefaultDBApi.<init>(DefaultDBApi.java:27)
at play.db.DefaultDBApi.class(DefaultDBApi.java:27)
while locating play.db.DefaultDBApi
while locating play.db.DBApi
for field at play.db.DBModule$NamedDatabaseProvider.dbApi(DBModule.java:61)
while locating play.db.DBModule$NamedDatabaseProvider
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.db.DBModule.bindings(DBModule.java:40):
Binding(interface play.db.Database qualified with QualifierInstance(#play.db.NamedDatabase(value=default)) to ProviderTarget(play.db.DBModule$NamedDatabaseProvider#3ec40700)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
Caused by: com.typesafe.config.ConfigException$WrongType: application.conf # file:/E:/workspace2/coup/target/scala-2.11/classes/application.conf: 344: pool has type STRING rather than OBJECT
I've tried so many different options and combinations, I'm out of ideas. Google doesn't even know the errors. Play just stops working and I have to restart it.

Try
jpa.default=readwritePU
db {
default {
hikaricp {
dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
dataSource {
serverName = localhost
databaseName = "mydbname"
user = "postgres"
password = "123456"
}
}
jndiName=ReadWriteDS
}
}

Related

Cannot make Bitronix manage my datasource/transactions in Spring Boot project

I have been trying to make JPAKnowledgeService for about 3 days now, and I am quite close to giving up, it just seems as too much configuration and detail work for what it is/does. However,
I had this problem initially, which is gone away after I added
java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory
into my jndi.properties file, as the answer suggests. I was able to create a StatefulKnowledgeSession finally, and thought the work is over. But in drools chat, the same guy suggested that my transactions may have been being handled by Hibernate instead of Bitronix, which might make my persistence non-transactional altogether.
And I guess he is right since whenever I tried to insert an Object into the Knowledge session and call fireAllRules, I was stuck at:
executing transaction with 0 enlisted resource
followed by:
transaction timed out: a Bitronix Transaction with GTRID [3132372E302E312E310000000000AFB9D800000006], status=MARKED_ROLLBACK, 0 resource(s) enlisted (started Thu Jan 01 05:11:56 EET 1970)
After that what I changed is; I updated my persistence.xml as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:comp/env/jdbc/jbpm</jta-data-source>
<class>org.drools.persistence.info.SessionInfo</class>
<properties>
<property name="hibernate.jndi.class" value="bitronix.tm.jndi.BitronixInitialContextFactory"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
</properties>
</persistence-unit>
</persistence>
added this line into my application.properties:
spring.datasource.jndi-name=java:comp/env/jdbc/jbpm
and gave a jndi name to my datasource for embedded tomcat by following these instructions.
and the error came back:
Caused by: java.lang.NullPointerException: null
at org.drools.persistence.jta.JtaTransactionManager.getStatus(JtaTransactionManager.java:273) ~[drools-persistence-jpa-6.5.0.Final.jar:6.5.0.Final]
at org.drools.persistence.jpa.AbstractPersistenceContextManager.getApplicationScopedEntityManager(AbstractPersistenceContextManager.java:78) ~[drools-persistence-jpa-6.5.0.Final.jar:6.5.0.Final]
at org.drools.persistence.jpa.JpaPersistenceContextManager.getApplicationScopedPersistenceContext(JpaPersistenceContextManager.java:55) ~[drools-persistence-jpa-6.5.0.Final.jar:6.5.0.Final]
at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:103) ~[drools-persistence-jpa-6.5.0.Final.jar:6.5.0.Final]
... 43 common frames omitted
The tables related to JPAKnowledgeService are created in the database, so I guess my JNDI registration is successful, but I don't seem to be able to find Bitronix as my transaction manager since JtaTransactionManager seems as null. What am I doing wrong? I am frustrated and clueless.
Apparently, I didn't have to register my default datasource as JNDI with Tomcat, but make Bitronix directly manage it as follows:
#Bean
public PoolingDataSource setupPoolingDataSource() {
PoolingDataSource pds = new PoolingDataSource();
pds.setUniqueName("jdbc/jbpm");
pds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
pds.setMaxPoolSize(50);
pds.setAllowLocalTransactions(true);
pds.getDriverProperties().put("user", "username");
pds.getDriverProperties().put("password", "password");
pds.getDriverProperties().put("url", "jdbc:mysql://localhost/databaseName?useUnicode=yes&characterEncoding=UTF-8&useSSL=false");
pds.getDriverProperties().put("driverClassName", "com.mysql.jdbc.Driver");
pds.init();
return pds;
}
and deleted these stuff:
#Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
return new TomcatEmbeddedServletContainerFactory() {
#Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
Tomcat tomcat) {
tomcat.enableNaming();
return super.getTomcatEmbeddedServletContainer(tomcat);
}
#Override
protected void postProcessContext(Context context) {
ContextResource resource = new ContextResource();
resource.setName(name);
resource.setType(DataSource.class.getName());
resource.setProperty("url", "...");
resource.setProperty("username", "...");
resource.setProperty("password", "...");
resource.setProperty("driverClassName", "...");
resource.setProperty("factory", "org.apache.tomcat.jdbc.pool.DataSourceFactory");
context.getNamingResources().addResource(resource);
}
};
}
#Bean
public DataSource jndiDataSource() throws IllegalArgumentException, NamingException {
JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
bean.setJndiName("...");
bean.setProxyInterface(DataSource.class);
bean.setLookupOnStartup(false);
bean.afterPropertiesSet();
return (DataSource)bean.getObject();
}
everything else stays the same and it works!

JavaEE + eclipseLink + TomEE gives java.sql.SQLSyntaxErrorException: user lacks privilege or object not found

I try to make a simple app using a rest service, eclipseLink and mysql.
I want to make this run on a TomEE server (apache-tomee-plume-1.7.4).
I deploy the app with eclipse.
The deployment seems to be ok
When I go to http://localhost:8080/eleve/ I'm getting :
javax.servlet.ServletException: Error processing webservice request
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:98)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
java.io.IOException: Failed to invoke AbstractHTTPDestination
org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:229)
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault:
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: ELEVE
Error Code: -5501
Call: SELECT ID, ADRESSE, classe, date_naissance, NOM, PRENOM, SEXE FROM ELEVE
Query: ReadAllQuery(referenceClass=Eleve sql="SELECT ID, ADRESSE, classe, date_naissance, NOM, PRENOM, SEXE FROM ELEVE")
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:324)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:240)
org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:227)
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Here is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="notePU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.test.eleve.model.Eleve</class>
<properties>
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/notes_eleves" />
<!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->
<property name="eclipselink.logging.level" value="INFO" />
</properties>
</persistence-unit>
</persistence>
I must be missing something but I can not find what.
I pushed my code here: gitlab
Thanks for your help
I finally managed to make it works on TomEE 1.7 and 7.
This is the changes I had to do:
Remove the database related properties from the persistence.xml
Replace non-jta-data-source tag by jta-data-source in persistence.xml
Put the mysql connector jar in my server /lib
In my server /conf/tomee.xml I have added myDatasource configuration as a resource.
Put #XmlRootElement(name = "eleve") over my Eleve entity (this seems to be only mandatory on TomEE <7)
At the end I think that my issue was that the datasource needs to be configure in the server conf in a EE context (datasource properties in persistence was just ignore I think, so it was like no one was declared) and the exception
user lacks privilege or object not found
was comming from the fact that:
If a DataSource is needed by the application and one is not declared,
TomEE will create one dynamically using default settings.
TomEE documentation
I'm not 100% sure of that explanation but at least the problem is solved, don't hesitate to put comments if I misunderstood something.
I have updated the gitlab project
Edit: Be aware that you can also configure the resource in a /WEB-INF/resources.xml file
Edit 2: If you are using Eclipse you can also face this issue if you wrongly configured your server location, it should be set to "use Tomcat installation (take control...)" and not "use workspace metadata"

Play + JPA + Hibernate + PostgreSQL: Cannot create Tables

I've been trying to create a simple and small application using Play Framework 2.4.0, JPA, and Hibernate 4.3.9 to connect to a PostgreSQL 9.4 database. I want the application to create new database tables based on the models created on the application. So far, I've had no success.
This is the content of my "build.sbt":
name := """aplicacion1"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaJpa,
//"org.apache.directory.api" % "apache-ldap-api" % "1.0.0-M14",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"org.hibernate" % "hibernate-core" % "4.3.9.Final",
"org.hibernate" % "hibernate-entitymanager" % "4.3.9.Final"
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
This is the content of my "application.conf" describing the database conection:
db.default.driver=org.postgresql.Driver
db.default.url="postgres://postgres:passsuper#localhost/tesis_play1"
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
This is the content of my "persistence.xml":
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
And this is the small model class I'm trying to get into the database:
#Entity
public class ruta {
#Id
public int idRuta;
public String nombre;
public boolean esIda;
public boolean esvuelta;
public String apodo1;
public String apodo2;
public String ref;
}
The application compiles and runs with no errors, but the "ruta" table is never created on the database. Is there something I'm missing? Thanks for the help!
EDIT: The following appears on the console when accessing the application through "localhost:9000":
[info] Compiling 2 Java sources to C:\Users\Enrique\Desktop\tesis_2\aplicacion1\target\scala-2.11\classes...
SLF4J: The following set of substitute loggers may have been accessed
SLF4J: during the initialization phase. Logging calls during this
SLF4J: phase were not honored. However, subsequent logging calls to these
SLF4J: loggers will work as normally expected.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
SLF4J: org.webjars.CloseQuietly
[info] - application - Creating Pool for datasource 'default'
[info] - play.api.db.HikariCPConnectionPool - datasource [jdbc:postgresql://localhost/tesis_play1] bound to JNDI as DefaultDS
[info] - play.api.db.DefaultDBApi - Database [default] connected at jdbc:postgresql://localhost/tesis_play1
[info] - play.api.libs.concurrent.ActorSystemProvider - Starting application default Akka system: application
[info] - play.api.Play$ - Application started (Dev)
Generated hbm2ddl database changes are called when Hibernate SessionFactory is created. Starting application does not create EntityManagerFactory and underlying Hibernate SessionFactory.
Changes on database will be made on first call to JPA, when EntityManagerFactory is created. To start EntityManagerFactory when your app starts, just create Global class with JPA call:
public class Global extends GlobalSettings {
public void onStart(Application app) {
JPA.withTransaction(new F.Callback0() {
#Override
public void invoke() throws Throwable {
play.Logger.debug("First JPA call");
}
});
}
public void onStop(Application app) {
}
}
Perhaps you could try to add this to your persistence.xml:
....
<property name="hibernate.archive.autodetection" value="class, hbm"/>
...
I'm no JPA expert myself but this seems like the only difference between your persistence.xml and the one I have in a project of mine. According to the docs this property will:
Determine which element is auto discovered by Hibernate Entity Manager while parsing the .par archive. (default to class,hbm).
It says it should default to class,hbm but I'd still try anyway. Outside of that the only other thing I could recommend is to try to add the database driver and credentials in the persistence.xml like:
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.connection.password" value="foobar"/>
<property name="hibernate.connection.url" value="jdbc:h2:mem:play"/>
<property name="hibernate.connection.username" value="sa"/>

Hibernate with Sql Server fail for nvarchar field with "No Dialect mapping..."

I'm using Hibernate's JPA-Implementation to access our SQL Server 2012 database.
When trying to select a nvarchar field in a native query, I get an exception "No Dialect mapping for JDBC type: -9".
It looks much like No Dialect mapping for JDBC type: -9 with Hibernate 4 and SQL Server 2012 or No Dialect mapping for JDBC type: -9 but I couldn't find a solution for me there (both are not using JPA).
My database setup:
CREATE TABLE NvarcharExample(
exampleField nvarchar(20) PRIMARY KEY
)
INSERT INTO NvarcharExample(exampleField) VALUES ('hello')
My code:
import java.io.IOException;
import javax.persistence.*;
#Entity
class NvarcharExample {
#Id
public String exampleField;
}
public class NvarcharTest {
public static void main(String[] args) throws IOException, InterruptedException {
String queryString = "SELECT e.exampleField FROM NvarcharExample e";
// establish connection
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("persistenceUnit");
try {
EntityManager entityManager = entityManagerFactory.createEntityManager();
// access data using JPQL
entityManager.createQuery(queryString).getResultList(); // works
// access data using SQL (native query)
entityManager.createNativeQuery(queryString).getResultList(); // fails
} finally {
entityManagerFactory.close();
}
}
}
My persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="persistenceUnit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<!-- database connection settings -->
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://<servername>:<port>;databaseName=<databasename>" />
<property name="javax.persistence.jdbc.user" value="<user>" />
<property name="javax.persistence.jdbc.password" value="<password>" />
</properties>
</persistence-unit>
</persistence>
With sql logging enable, I get this output in my console
select nvarcharex0_.exampleField as col_0_0_ from NvarcharExample nvarcharex0_
SELECT e.exampleField FROM NvarcharExample e
I'm using
hibernate-core-4.3.10.Final.jar
hibernate-entitymanager-4.3.10.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
hibernate-commons-annotations-4.0.5.Final.jar
sqljdbc41.jar
What I've tried:
using a varchar instead of nvarchar makes it work, but I need nvarchar
using jpql instead of sql works (see my example code), but I need a native query
I tried sqljdbc4.jar in Version 4.0 and 4.1 and I tried sqljdbc41.jar
I head about subclassing the SQL Server Dialect class, but did not have any success with that
I added <property name="dialect" value="org.hibernate.dialect.SQLServerDialect" /> to my persistence.xml (right behind the password property)
I added <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" /> to my persistence.xml
I changed the persistence provider to <provider>org.hibernate.ejb.HibernatePersistence</provider>
Using #Nationalized attribute helped me to map String to nvarchar for MS SQL 2012 without dialect subclassing.
At the same time setting the hibernate.use_nationalized_character_data property to true did not worked for me.
For futher information watch docs National Character Types.
I was able to resolve that issue by subclassing the SQLServerDialect:
package packagename;
import java.sql.Types;
public class SqlServerDialectWithNvarchar extends org.hibernate.dialect.SQLServerDialect {
public SqlServerDialectWithNvarchar() {
registerHibernateType(Types.NVARCHAR, 4000, "string");
}
}
and referencing it in my persistence.xml:
<property name="hibernate.dialect" value="packagename.SqlServerDialectWithNvarchar" />
PS: It seems to be fixed with hibernate 5.1 according to this ticket: https://hibernate.atlassian.net/browse/HHH-10183

Embedded Java DB from within Felix?

I assume there's a way to use an embedded Java DB instance within a standalone Felix 4.0.2 OSGi box. However I can't seem to find any clues as to how I should setup the whole thing: What implementation bundles should I use? How should I set it up?
I tried quite a few things, including getting the dedicated bundles from a glassfich 3.1.2 install, but whatever I do no persistence manager is registered by the framework to provide my app with.
My code otherwise follows all academical precepts, with a a ServiceTracker being registered to find out about EntityManagerFactory registrations, but none is found...
Here's my persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="com.julianware.toolbox.logbacktracker.pu"
transaction-type="RESOURCE_LOCAL">
<!-- mapping-file>META-INF/maintenance_orm.xml</mapping-file>
<mapping-file>META-INF/vehicle_orm.xml</mapping-file -->
<class>com.julianware.toolbox.logbacktracker.pu.LoggerEvent</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:database;create=true" />
<property name="javax.persistence.jdbc.user" value="felix" />
<property name="javax.persistence.jdbc.password" value="felix" />
</properties>
</persistence-unit>
And my Activator's start() method:
public void start(final BundleContext context) throws Exception {
Filter filter = context.createFilter(String.format("(&(%s=%s)(%s=%s))",
OBJECTCLASS, EntityManagerFactory.class.getName(),
EntityManagerFactoryBuilder.JPA_UNIT_NAME, "com.julianware.toolbox.logbacktracker.pu")
);
entityManagerFactoryTracker = new ServiceTracker(context, filter, new ServiceTrackerCustomizer() {
#Override
public void removedService(ServiceReference reference, Object service) {}
#Override
public void modifiedService(ServiceReference reference, Object service) {}
#Override
public Object addingService(ServiceReference reference) {
logger.debug("Found Entity Manager Service reference.");
entityManagerFactory = (EntityManagerFactory) context.getService(reference);
return entityManagerFactory;
}
});
entityManagerFactoryTracker.open();
}
Last, I'm on JDK 7. Java DB implementation is that of the jdk install.
Does anyone know anything?
Mighty thanks.
Julian
I'm not sure, but you could try Derby from Maven Central. It should contain the correct OSGi meta data.

Categories