Im am trying to use Hibernate Search together with Play Framework. It seams very easy and straight forward. But I get a exception (see below):
Here is what I did:
I added dependencies
"org.hibernate" % "hibernate-entitymanager" % "4.3.8.Final",
"org.hibernate" % "hibernate-search-orm" % "5.2.0.Final",
I already had Entitymanager and it works fine.
Then I added the Hibernate Search properties:
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<class>models.User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.search.default.directory_provider"
value="filesystem"/>
<property name="hibernate.search.default.indexBase"
value="/var/lucene/indexes"/>
</properties>
</persistence-unit>
New about this is only:
<property name="hibernate.search.default.directory_provider"
value="filesystem"/>
<property name="hibernate.search.default.indexBase"
value="/var/lucene/indexes"/>
I added some Annotation to the User:
#Entity
#Indexed
public class User extends Model {
#Field(index= Index.YES, analyze= Analyze.YES, store= Store.NO)
public String firstname;
#Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
public String lastname;
}
I start the Server and try to access the site:
play.api.UnexpectedException: Unexpected exception[AbstractMethodError: org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.getConfigurationValues()Ljava/util/Map;]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:170) ~[play_2.11-2.3.7.jar:2.3.7]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.3.7.jar:2.3.7]
at scala.Option.map(Option.scala:145) ~[scala-library-2.11.4.jar:na]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:130) ~[play_2.11-2.3.7.jar:2.3.7]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:128) ~[play_2.11-2.3.7.jar:2.3.7]
Caused by: java.lang.AbstractMethodError: org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.getConfigurationValues()Ljava/util/Map;
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:404) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) ~[hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) ~[hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
Thank you for your Help.
All Hibernate Search versions from 5.0.0 to 5.3.0 are compatible with any Hibernate ORM version 4.3.x (4.3.0 to latest of the 4.3 series, which currently is 4.3.10).
But you always must choose the same exact version for hibernate-entitymanager and hibernate-orm, as these are released together and should not be split & mixed up.
From the stacktrace it seems you were already using Hibernate ORM version 4.3.9 (hibernate-core-4.3.9.Final.jar), so you should not use hibernate-entitymanager-4.3.8.Final but either upgrade EntityManager to 4.3.9 as well, or downgrade hibernate-core to 4.3.8, or just upgrade both to 4.3.10 (probably the best option).
Hibernate compatibility rules
Generally the rule is that hibernate-core and hibernate-entitymanager need to be at the exact same version; then consult the Hibernate Search documentation to find out for which range it is compatible.
This information can be found in the README, in the reference documentation, or via the pom.xml (also with the many tools able to interpret Maven metadata).
Compatibility is also mentioned in the downloads page:
- http://hibernate.org/search/downloads/
The downloads page and the pom file only mention a single, specific Hibernate ORM version (the version it was built with).
The README and reference documentation specify the range of versions which are meant to be compatible; these are updated by humans though so it might occasionally be less accurate, but if that wouldn't work please file a bug as we do strive to keep compatibility ranges relaxed, especially among minor versions.
The Compatibility definitions and expectations for Hibernate are documented here: https://github.com/hibernate/hibernate-orm/wiki/Compatibility-Considerations
Solved thanks to User mhlz in the comments.Seams I had to update the Entity-manager.
Yes I've already searched here for this question but I have this problem after the researches.
So, I'm making a simple standalone project, containing only Entities and DAOs.
I'm using IntelliJ.
EDIT: My DB connection informations are good, I'm sure. And I've got another project (GWT) and I'm using the same method -> it works
My META-INF folder is in the root src folder, so this is my persistence.xml:
`<persistence-unit name="jpa">
<!--<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<class>ejbpersistance.entities.User</class>
<class>ejbpersistance.entities.Comment</class>
<class>ejbpersistance.entities.Article</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/ejb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>`
and this is my code:
public EntityManagerFactory getEntityManagerFactory() {
if(emf == null)
emf = Persistence.createEntityManagerFactory("jpa");
return emf;
}
I tried with Hibernate provider, Eclipse provider but always this problem.
Can someone help me ? And if I missed something in another topic concerning this issue, I apologize for the time loss.
The location of the persistence unit is the issue here.
check if persistence.xml is in your classpath:
If it is non-Java EE application(j2SE)
The jar file or directory whose META-INF directory contains the persistence.xml
file is termed the root of the persistence unit.please check classpath location in your IDE, Eclipse: Project Properties -> Java Build Path -> ****.
check if hibernate provider is in your classpath
once you can try to uncomment the provider line in your P.xml file
org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
Thanks
Make sure persistence.xml is in the META-INF directory and the class path includes the META-INF parent directory.
You also didn't show the complete persistence.xml. The surrounding <persistence> tag must include the proper namespace, e.g.
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence">
...
</persistence>
I need to add geospatial information, "Points" to be specific, to entries of a MySQL database (v5.5.28). I tried to map the created column "location" to the corresponding property of my java EJB entity ServiceInfo, using the simple code:
#Column(name = "location")
private com.vividsolutions.jts.geom.Point location;
However, this causes the following error:
Exception [EclipseLink-66] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Could not deserialize object from byte array.
Internal Exception: java.io.StreamCorruptedException: invalid stream header: 00000000
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[location-->ServiceInfo.location]
Descriptor: RelationalDescriptor(ies.persistence.entity.ServiceInfo --> [DatabaseTable(ServiceInfo)])
at org.eclipse.persistence.exceptions.DescriptorException.notDeserializable(DescriptorException.java:1218)
at org.eclipse.persistence.mappings.converters.SerializedObjectConverter.convertDataValueToObjectValue(SerializedObjectConverter.java:72)
...
I think the problem is the java mysql connector (v5.1.22) doesn't support geospatial information, which surprises me since the database does. Can someone confirm this is the case, or tell me what I might be doing wrong and point me in the right direction?
I'm working in Netbeans 7.2, using JDK 1.7 and a GlassFish Server 3.1.2
Ok, so I finally fixed my problem by making the following changes to my persistence tier:
I switched from a MySQL database to a PostgeSQL database, using the spatial extension PostGIS. The reason for this is that MySQL only partially implements the OpenGIS specifications.
Next, I had to change the persistence unit of EclipseLink (JPA 2.0)(Default) to Hibernate (JPA 2.0).
Jars to include in the classpath of both my project and glassfish (which seemed to be unable to find them otherwise. I had to copy them to the root of domain1) are:
postgresql-9.2-1002.jdbc4.jar
postgis-jdbc-2.1.0SVN.jar
Hibernate 4.1.8 (all required jars, ehcache for the optional ones and hibernate-entitymanager-4.1.8.Final.jar for JPA... These are all included in the release bundle)
hibernate-spatial-4.0-M1.jar (hibernate-spatial-1.1.1.jar and hibernate-spatial-postgis-1.1.1.jar are NOT compatible with Hibernate 4.x!).
jts-1.8.jar
The resulting persistence.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="IES-ejbPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/postgresql_iesdb3</jta-data-source>
<class>ies.persistence.entity.ServiceInfo</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
The annotations to use for my EJB entitiy are:
#Type(type="org.hibernate.spatial.GeometryType")
#Column(name = "location", columnDefinition="Geometry")
private com.vividsolutions.jts.geom.Geometry location;
We now have a proper mapping using Hibernate + JPA + PostgeSQL/PostGIS.
I am currently working on an OSGi project on Felix (v4.0.3). I need to use JPA so I have installed the Apache Aries JPA bundles. I also installed OpenJPA and I need it to connect to a MySQL Database, using the MySQL Connector Bundle. Unfortunately it does not work, OpenJPA says it cannot find the MySQL JDBC class and I cannot figure out what's broken, maybe I am doing something wrong. I'll explain below what I installed precisely along with the persistence.xml file and the actual exception I get.
Here's the list of the Apache Aries bundles I installed :
org.apache.aries.jpa.api-0.3.jar
org.apache.aries.jpa.container.context-0.3.jar
org.apache.aries.jpa.container-0.3.jar
org.apache.aries.util-0.4.jar
I then installed the dependencies of those Apache Aries JPA bundles. I downloaded them from Springsource :
com.springsource.javax.transaction-1.1.0.jar
com.springsource.org.apache.log4j-1.2.16.jar
com.springsource.slf4j.api-1.6.1.jar
com.springsource.slf4j.log4j-1.6.1.jar
javax.persistence_2.0.4.v201112161009.jar (this one is from EclipseLink in case it matters)
I also installed OpenJPA and all its dependencies. I found bundles 2 to 5 (commons-*) in the lib folder of the apache-openjpa-2.2.0 downloaded folder. I downloaded Serp here because the jar found in the lib folder wasn't an OSGi bundle. Finally I found the last two bundles (#7 and #8) in Springsource :
openjpa-2.2.0.jar
commons-collections-3.2.1.jar
commons-dbcp-1.4.jar
commons-lang-2.4.jar
commons-pool-1.5.4.jar
org.apache.servicemix.bundles.serp-1.13.1_4.jar
com.springsource.javax.servlet-2.5.0.jar
com.springsource.org.objectweb.asm-3.2.0.jar
Once I finally had OpenJPA installed, I still needed the MySQL JDBC Driver bundle, which I also got from the Springsource repository along with its commons-logging dependency :
com.springsource.com.mysql.jdbc-5.1.6.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
Now at this point the list of bundles installed is getting quite large. I said I installed OpenJPA but it's only because I could not figure out how to use any other provider with Aries. I initially wanted to use EclipseLink but apparently Apache Aries does not detect it as a provider and according to this blog you have to make yet another bundle containing your own activator for Aries to notice EclipseLink. I tried it but it didn't work so I fell back on using OpenJPA instead.
So now I have two questions :
How can I make OpenJPA notice my MySQL Bundle ?
OR alternatively :
How can I make Apache Aries notice EclipseLink ?
Here's the persistence.xml file I use :
<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_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="userManager.model" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>org.project.dao.entity.UserEntity</class>
<properties>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/usermanager?autoReconnect=true" />
<property name="openjpa.ConnectionUserName" value="root" />
<property name="openjpa.ConnectionPassword" value="root" />
</properties>
</persistence-unit>
</persistence>
The error occurs when the following Constructor of my DAO class is executed :
#PersistenceContext(unitName="userManager.model")
private EntityManager em;
private EntityManagerFactory emf;
public UserDAOBean() {
em = emf.createEntityManager();
}
Here's the error I get with OpenJPA not finding MySQL. Of course it is worth mentioning that both the URL and the username/password do work :
<openjpa-2.2.0-r422266:1244990 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.2.0-r422266:1244990 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "com.mysql.jdbc.Driver" and URL "jdbc:mysql://localhost:3306/usermanager?autoReconnect=true". You may have specified an invalid URL.
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:255)
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:123)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:844)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:732)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:295)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1671)
at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:646)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:203)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
at org.apache.aries.jpa.container.impl.CountingEntityManagerFactory.createEntityManager(CountingEntityManagerFactory.java:64)
at javax.persistence.EntityManagerFactory$$Proxy.createEntityManager(Unknown Source)
I've cut the exception (it keeps going on and on) until this point :
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found by org.apache.openjpa [12]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1460)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:85)
... 108 more
PS: I couldn't post the links to Aries, OpenJPA or EclipseLink because of the spam restriction, sorry :/
Thanks to Holly Cummins and after another bunch of hours of research, I've been able to find a solution to my problem. I'll detail it below, this is going to be a very long answer.
If you want to use EclipseLink with Apache Aries (which I find orders of magnitude simpler to install than OpenJPA for OSGi because it's contained in only 5 bundles), you will have to checkout the EclipseLink - Aries adapter directly from apache because it has not been released yet.
Go to an appropriate folder and execute the following command to get it :
svn checkout https://svn.apache.org/repos/asf/aries/trunk/jpa/jpa-container-eclipselink-adapter/
You should get a folder named jpa-container-eclipselink-adapter. Now, assuming that you are using Linux and have Maven installed, run the following commands :
cd jpa-container-eclipselink-adapter
mvn clean install
Once Maven has successfully compiled the source of the adapter, you will find it in your Maven repository using the path
<maven-repo>/org/apache/aries/jpa/org.apache.aries.jpa.eclipselink.adapter/0.3.1-SNAPSHOT/org.apache.aries.jpa.eclipselink.adapter-0.3.1-SNAPSHOT.jar
You'll have to deploy this bundle with the others (copying it in the bundle folder for Felix).
So that was for the EclipseLink part, now in order to make your persistence actually work you'll have to use Blueprint with Aries. Here is the list of all the bundles you'll need to get from the [http://aries.apache.org/downloads/currentrelease.html](Apache Aries download page)
org.apache.aries.blueprint
org.apache.aries.proxy
org.apache.aries.jndi.api
org.apache.aries.jndi
org.apache.aries.blueprint
org.apache.aries.jpa.api
org.apache.aries.jpa.container.context
org.apache.aries.jpa.container
org.apache.aries.transaction.blueprint
org.apache.aries.transaction.manager (This one is listed twice on their site, it's just a duplicate)
org.apache.aries.util
Once you're done downloading Aries, you still need dependencies (get them from SpringSource). These are the bundles for SLF4J, Log4J, SLF4J Log4J Binding and javax.transaction 1.1 API.
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.slf4j.api&version=1.6.1
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.slf4j.log4j&version=1.6.1
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.javax.transaction&version=1.1.0
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.org.apache.log4j&version=1.2.16
You'll also need the bundles from EclipseLink (you need the OSGi bundle version)
http://www.eclipse.org/eclipselink/downloads/
Open the zip and get the following files :
org.eclipse.persistence.antlr
org.eclipse.persistence.asm
org.eclipse.persistence.core
org.eclipse.persistence.jpa
javax.persistence
Finally, assuming that you want to use a MySQL database, you'll need the bundles for the MySQL JDBC Driver (downloaded from Springsource)
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.mysql.jdbc&version=5.1.6
http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.org.apache.commons.logging&version=1.1.1
Once you have all those bundles installed, you need to use a non-jta-datasource that you will get through JNDI. Here's a persistence.xml file that you can change for your needs :
<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_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="userManager" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/userManagerDS)</non-jta-data-source>
<class>com.example.dao.entity.UserEntity</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<!-- EclipseLink should create the database schema automatically -->
<!-- <property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" /> -->
</properties>
</persistence-unit>
</persistence>
See the javax.sql.Datasource in the non-jta-data-source tag ? That's what we'll define using Blueprint xml.
In order to do so, you'll first need to add the OSGI-INF/blueprint/ folders in your persistence bundle (the one containing your DAOs and Entities). This is the default folder where blueprint xml files are located, any xml file located here will be scanned. Once that's done, create the blueprint.xml file (the name can be changed) and paste (and modify) the following code :
<bean id="dataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/usermanager?autoReconnect=true" />
<property name="user" value="root" />
<property name="password" value="root" />
</bean>
<service id="MySQLDataSource" interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/userManagerDS" />
</service-properties>
</service>
<service id="userDAOService" interface="com.example.dao.remote.UserDAORemote">
<bean class="com.example.dao.beans.UserDAOBean">
<jpa:unit index="0" unitname="userManager" />
</bean>
</service>
</blueprint>
Here, we are doing two things. First, we tell Aries to create the userManagerDS datasource and configure it with the JDBC Driver, URL, user and password. This is the same datasource that we used in the persistence.xml file.
Then, we inject the EntityManagerFactory in our DAO. Our DAO is the com.example.dao.beans.UserDAOBean class, we need to add its name to the bean tag. This class will have to implement an interface and we'll need to add this interface to the service tag. Now the final jpa:unit tag tells Aries to inject the EntityManagerFactory related to the persistence unit called userManager (the same name we used in the persistence.xml) by using the first constructor of UserDAOBean. This is done by using the index="0" attribute. This also means you have to have some code like the following in your DAO :
private EntityManager em;
private EntityManagerFactory emf;
public UserDAOBean(EntityManagerFactory emf) {
this.emf = emf;
this.em = emf.createEntityManager();
}
It's also possible to inject the EMF using a setter. Here are further resources to help you use Blueprint :
http://aries.apache.org/modules/jpaproject.html
http://aries.apache.org/modules/blueprint.html
http://mail-archives.apache.org/mod_mbox/aries-user/201104.mbox/%3C15F2C30E-2A71-4320-9992-DBCF181B58E4#gmail.com%3E
Optional : Be careful, if you are using Felix, adding the javax.transaction bundle will cause a "uses constraint violation" because the system bundle (bundle 0) also exports this API. You'll have to keep it from exporting it by changing the following line in the config.properties :
#org.osgi.framework.system.packages=
You'll have to put in here the list of all the packages that the previous bundle exported. Unfortunately, there's no way to "remove" a package, you have to redefine the entire list of packages to be exported. Here's mine, I hope it helps (yes it is very, very long) :
org.osgi.framework.system.packages=org.osgi.framework;version=1.6.0, org.osgi.framework.launch;version=1.0.0, org.osgi.framework.wiring;version=1.0.0, org.osgi.framework.startlevel;version=1.0.0, org.osgi.framework.hooks.bundle;version=1.0.0, org.osgi.framework.hooks.resolver;version=1.0.0, org.osgi.framework.hooks.service;version=1.1.0, org.osgi.framework.hooks.weaving;version=1.0.0, org.osgi.service.packageadmin;version=1.2.0, org.osgi.service.startlevel;version=1.1.0, org.osgi.service.url;version=1.0.0, org.osgi.util.tracker;version=1.5.0, javax.accessibility;version=0.0.0.1_006_JavaSE, javax.activation;version=0.0.0.1_006_JavaSE, javax.activity;version=0.0.0.1_006_JavaSE, javax.annotation.processing;version=0.0.0.1_006_JavaSE, javax.annotation;version=0.0.0.1_006_JavaSE, javax.crypto.interfaces;version=0.0.0.1_006_JavaSE, javax.crypto.spec;version=0.0.0.1_006_JavaSE, javax.crypto;version=0.0.0.1_006_JavaSE, javax.imageio.event;version=0.0.0.1_006_JavaSE, javax.imageio.metadata;version=0.0.0.1_006_JavaSE, javax.imageio.plugins.bmp;version=0.0.0.1_006_JavaSE, javax.imageio.plugins.jpeg;version=0.0.0.1_006_JavaSE, javax.imageio.spi;version=0.0.0.1_006_JavaSE, javax.imageio.stream;version=0.0.0.1_006_JavaSE, javax.imageio;version=0.0.0.1_006_JavaSE, javax.jws.soap;version=0.0.0.1_006_JavaSE, javax.jws;version=0.0.0.1_006_JavaSE, javax.lang.model.element;version=0.0.0.1_006_JavaSE, javax.lang.model.type;version=0.0.0.1_006_JavaSE, javax.lang.model.util;version=0.0.0.1_006_JavaSE, javax.lang.model;version=0.0.0.1_006_JavaSE, javax.management.loading;version=0.0.0.1_006_JavaSE, javax.management.modelmbean;version=0.0.0.1_006_JavaSE, javax.management.monitor;version=0.0.0.1_006_JavaSE, javax.management.openmbean;version=0.0.0.1_006_JavaSE, javax.management.relation;version=0.0.0.1_006_JavaSE, javax.management.remote.rmi;version=0.0.0.1_006_JavaSE, javax.management.remote;version=0.0.0.1_006_JavaSE, javax.management.timer;version=0.0.0.1_006_JavaSE, javax.management;version=0.0.0.1_006_JavaSE, javax.naming.directory;version=0.0.0.1_006_JavaSE, javax.naming.event;version=0.0.0.1_006_JavaSE, javax.naming.ldap;version=0.0.0.1_006_JavaSE, javax.naming.spi;version=0.0.0.1_006_JavaSE, javax.naming;version=0.0.0.1_006_JavaSE, javax.net.ssl;version=0.0.0.1_006_JavaSE, javax.net;version=0.0.0.1_006_JavaSE, javax.print.attribute.standard;version=0.0.0.1_006_JavaSE, javax.print.attribute;version=0.0.0.1_006_JavaSE, javax.print.event;version=0.0.0.1_006_JavaSE, javax.print;version=0.0.0.1_006_JavaSE, javax.rmi.CORBA;version=0.0.0.1_006_JavaSE, javax.rmi.ssl;version=0.0.0.1_006_JavaSE, javax.rmi;version=0.0.0.1_006_JavaSE, javax.script;version=0.0.0.1_006_JavaSE, javax.security.auth.callback;version=0.0.0.1_006_JavaSE, javax.security.auth.kerberos;version=0.0.0.1_006_JavaSE, javax.security.auth.login;version=0.0.0.1_006_JavaSE, javax.security.auth.spi;version=0.0.0.1_006_JavaSE, javax.security.auth.x500;version=0.0.0.1_006_JavaSE, javax.security.auth;version=0.0.0.1_006_JavaSE, javax.security.cert;version=0.0.0.1_006_JavaSE, javax.security.sasl;version=0.0.0.1_006_JavaSE, javax.sound.midi.spi;version=0.0.0.1_006_JavaSE, javax.sound.midi;version=0.0.0.1_006_JavaSE, javax.sound.sampled.spi;version=0.0.0.1_006_JavaSE, javax.sound.sampled;version=0.0.0.1_006_JavaSE, javax.sql.rowset.serial;version=0.0.0.1_006_JavaSE, javax.sql.rowset.spi;version=0.0.0.1_006_JavaSE, javax.sql.rowset;version=0.0.0.1_006_JavaSE, javax.sql;version=0.0.0.1_006_JavaSE, javax.swing.border;version=0.0.0.1_006_JavaSE, javax.swing.colorchooser;version=0.0.0.1_006_JavaSE, javax.swing.event;version=0.0.0.1_006_JavaSE, javax.swing.filechooser;version=0.0.0.1_006_JavaSE, javax.swing.plaf.basic;version=0.0.0.1_006_JavaSE, javax.swing.plaf.metal;version=0.0.0.1_006_JavaSE, javax.swing.plaf.multi;version=0.0.0.1_006_JavaSE, javax.swing.plaf.synth;version=0.0.0.1_006_JavaSE, javax.swing.plaf;version=0.0.0.1_006_JavaSE, javax.swing.table;version=0.0.0.1_006_JavaSE, javax.swing.text.html.parser;version=0.0.0.1_006_JavaSE, javax.swing.text.html;version=0.0.0.1_006_JavaSE, javax.swing.text.rtf;version=0.0.0.1_006_JavaSE, javax.swing.text;version=0.0.0.1_006_JavaSE, javax.swing.tree;version=0.0.0.1_006_JavaSE, javax.swing.undo;version=0.0.0.1_006_JavaSE, javax.swing;version=0.0.0.1_006_JavaSE, javax.tools;version=0.0.0.1_006_JavaSE, javax.transaction.xa;version=0.0.0.1_006_JavaSE, javax.transaction;version=0.0.0.1_006_JavaSE, javax.xml.bind.annotation.adapters;version=0.0.0.1_006_JavaSE, javax.xml.bind.annotation;version=0.0.0.1_006_JavaSE, javax.xml.bind.attachment;version=0.0.0.1_006_JavaSE, javax.xml.bind.helpers;version=0.0.0.1_006_JavaSE, javax.xml.bind.util;version=0.0.0.1_006_JavaSE, javax.xml.bind;version=0.0.0.1_006_JavaSE, javax.xml.crypto.dom;version=0.0.0.1_006_JavaSE, javax.xml.crypto.dsig.dom;version=0.0.0.1_006_JavaSE, javax.xml.crypto.dsig.keyinfo;version=0.0.0.1_006_JavaSE, javax.xml.crypto.dsig.spec;version=0.0.0.1_006_JavaSE, javax.xml.crypto.dsig;version=0.0.0.1_006_JavaSE, javax.xml.crypto;version=0.0.0.1_006_JavaSE, javax.xml.datatype;version=0.0.0.1_006_JavaSE, javax.xml.namespace;version=0.0.0.1_006_JavaSE, javax.xml.parsers;version=0.0.0.1_006_JavaSE, javax.xml.soap;version=0.0.0.1_006_JavaSE, javax.xml.stream.events;version=0.0.0.1_006_JavaSE, javax.xml.stream.util;version=0.0.0.1_006_JavaSE, javax.xml.stream;version=0.0.0.1_006_JavaSE, javax.xml.transform.dom;version=0.0.0.1_006_JavaSE, javax.xml.transform.sax;version=0.0.0.1_006_JavaSE, javax.xml.transform.stax;version=0.0.0.1_006_JavaSE, javax.xml.transform.stream;version=0.0.0.1_006_JavaSE, javax.xml.transform;version=0.0.0.1_006_JavaSE, javax.xml.validation;version=0.0.0.1_006_JavaSE, javax.xml.ws.handler.soap;version=0.0.0.1_006_JavaSE, javax.xml.ws.handler;version=0.0.0.1_006_JavaSE, javax.xml.ws.http;version=0.0.0.1_006_JavaSE, javax.xml.ws.soap;version=0.0.0.1_006_JavaSE, javax.xml.ws.spi;version=0.0.0.1_006_JavaSE, javax.xml.ws.wsaddressing;version=0.0.0.1_006_JavaSE, javax.xml.ws;version=0.0.0.1_006_JavaSE, javax.xml.xpath;version=0.0.0.1_006_JavaSE, javax.xml;version=0.0.0.1_006_JavaSE, org.ietf.jgss;version=0.0.0.1_006_JavaSE, org.omg.CORBA.DynAnyPackage;version=0.0.0.1_006_JavaSE, org.omg.CORBA.ORBPackage;version=0.0.0.1_006_JavaSE, org.omg.CORBA.TypeCodePackage;version=0.0.0.1_006_JavaSE, org.omg.CORBA.portable;version=0.0.0.1_006_JavaSE, org.omg.CORBA;version=0.0.0.1_006_JavaSE, org.omg.CORBA_2_3.portable;version=0.0.0.1_006_JavaSE, org.omg.CORBA_2_3;version=0.0.0.1_006_JavaSE, org.omg.CosNaming.NamingContextExtPackage;version=0.0.0.1_006_JavaSE, org.omg.CosNaming.NamingContextPackage;version=0.0.0.1_006_JavaSE, org.omg.CosNaming;version=0.0.0.1_006_JavaSE, org.omg.Dynamic;version=0.0.0.1_006_JavaSE, org.omg.DynamicAny.DynAnyFactoryPackage;version=0.0.0.1_006_JavaSE, org.omg.DynamicAny.DynAnyPackage;version=0.0.0.1_006_JavaSE, org.omg.DynamicAny;version=0.0.0.1_006_JavaSE, org.omg.IOP.CodecFactoryPackage;version=0.0.0.1_006_JavaSE, org.omg.IOP.CodecPackage;version=0.0.0.1_006_JavaSE, org.omg.IOP;version=0.0.0.1_006_JavaSE, org.omg.Messaging;version=0.0.0.1_006_JavaSE, org.omg.PortableInterceptor.ORBInitInfoPackage;version=0.0.0.1_006_JavaSE, org.omg.PortableInterceptor;version=0.0.0.1_006_JavaSE, org.omg.PortableServer.CurrentPackage;version=0.0.0.1_006_JavaSE, org.omg.PortableServer.POAManagerPackage;version=0.0.0.1_006_JavaSE, org.omg.PortableServer.POAPackage;version=0.0.0.1_006_JavaSE, org.omg.PortableServer.ServantLocatorPackage;version=0.0.0.1_006_JavaSE, org.omg.PortableServer.portable;version=0.0.0.1_006_JavaSE, org.omg.PortableServer;version=0.0.0.1_006_JavaSE, org.omg.SendingContext;version=0.0.0.1_006_JavaSE, org.omg.stub.java.rmi;version=0.0.0.1_006_JavaSE, org.w3c.dom.bootstrap;version=0.0.0.1_006_JavaSE, org.w3c.dom.events;version=0.0.0.1_006_JavaSE, org.w3c.dom.ls;version=0.0.0.1_006_JavaSE, org.w3c.dom;version=0.0.0.1_006_JavaSE, org.xml.sax.ext;version=0.0.0.1_006_JavaSE, org.xml.sax.helpers;version=0.0.0.1_006_JavaSE, org.xml.sax;version=0.0.0.1_006_JavaSE
You may have better luck using a JNDI datasource rather than a direct jdbc connection. The Aries blog sample has a blog.datasource bundle which registers a datasource using Blueprint. The list of required bundles is longer than what you currently have, but you can just copy them all from the blog-assembly/target directory or pom.xml.
Alternatively, Aries have an org.apache.aries.jpa.eclipselink.adapter which does the same thing as the article you linked to. Aries use it for testing against EclipseLink, so it definitely should work. You could also look at the Aries tests to see how it's used and see if there's an EclipseLink test you can copy.
Things may be easier when using the gemini blueprint dbAccess plugin (http://www.eclipse.org/gemini/dbaccess/) , which I think will work for Aries as well. For MySQL be sure to include the connector plugin (e.g. http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.mysql.jdbc&version=5.1.6). This should be sufficient to get the database up and running, provided the blueprint.xml (to use the example above) is configured properly, as above.
I am still new to Java and Eclipse and I'm trying to get my application to connect to a database. I think I want to use EclipseLink, but all of the documentation on the matter assumes you already know everything there is to know about everything.
I keep getting linked back to this tutorial: http://www.vogella.de/articles/JavaPersistenceAPI/article.html
But it's basically useless because it doesn't tell you HOW to do anything. For the Installation section, it tells you to download EclipseLink and gives you a link to the download page, but doesn't tell you what to do with it after you download. The download page doesn't either. I used the "Install new software" option in Eclipse to install EclipseLink into Eclipse, but it gave me like 4 different options, none of which are explained anywhere. It gave me options JPA, MOXy, SDO, etc, but I don't know which one I need. I just installed them all. Everything on the web assumes you are already a Java guru and things that are second nature to Java devs are never explained, so it's very frustrating for someone trying to learn.
So how do I install and USE EclipseLink in my project and what do I need to do to connect it to a Microsoft SQL server? Again, I am new to all of this so I have no clue what to do. Thanks for the help.
I don't think you need to just learn how to use EclipseLink. EclipseLink is a reference implementation for JPA. There are a number of tutorials on the web that you can read up about regarding JPA. I have written a series of articles for beginners for building web applications and one of the sections deals with JPA (and EclipseLink). If you are interested take a look and I welcome discussion on it to improve it as well as my own understanding.
EDIT: Here's a more direct answer to your question. I hope it helps
There are a number of different download approaches to take for EclipeLink. This is one way:
Download EclipseLink Installer
Extract the eclipselink.jar from the download jlib directory and include it in your projects classpath.
Download the ejb3-persistence.jar and include it in your projects classpath.
I haven't got SQL server myself but you would need to include the sqljdbc jar in your classpath. Don't know what version you are using or if it even matters but you can try this link and download the 1033\sqljdbc_3.0.1301.101_enu.tar.gz file. Extract it and copy the sqljdbc.jar into your projects classpath.
Here's a simple standalone example:
persistence.xml (saved in your META-INF directory in your src folder)
<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="escribs-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<!-- haven't tested with SQL server so hope the below is correct -->
<property name="eclipselink.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="eclipselink.jdbc.url" value="jdbc:sqlserver://localhost;databaseName=MyDB" />
<property name="eclipselink.jdbc.user" value="myusername" />
<property name="eclipselink.jdbc.password" value="mypassword" />
</properties>
</persistence-unit>
</persistence>
Entity class:
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="person")
public class Person {
private Long id;
private String name;
#Id
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
SimpleTest
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
public class SimpleTest {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("escribs-pu");
Person person = new Person();
person.setId(1L);
person.setName("Clark");
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
em.persist(person);
tx.commit();
System.out.println("Person id: " + person.getId());
} catch (RuntimeException e) {
tx.rollback();
throw e;
} finally {
if (em != null && em.isOpen()) {
em.close();
}
}
}
}
"So how do I install and USE EclipseLink in my project
Since none of the previous answers really answer the question "How do I add the jpa impl. libraries to eclipse", here's the answer (took me an hour to figure it out myself!):
download a JPA implementation, for example eclipselink-2.5.1.v20130918-f2b9fc5.zip and extract the implementation libs. For example: eclipselink.jar jpa/*.jar to a directory
In eclipse open window -> preferences. In preferences window open build path -> user libraries
In user libraries click on new, type "name jpa" => ok
click on jpa and click "add external jars ... and select all extracted impl libraries
After that you can complete vogella's tutorial.
To the admins: You might want to flag the previous comments as invalid/offtopic. Especially you don't put the jars to the project path, as you are about to create a NEW project. However, the question is too broad, too.
No one mentioned a way to install EclipseLink libraries with the help of Maven. If you have a Maven project and manage your dependencies with Maven you can simply add following dependency and EclipseLink libraries are going to be able for your use in your project:
<!-- https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.6</version>
</dependency>
You can find other versions of EclipseLink here. After you add and download Maven dependency, you can set up persistence.xml as mentioned in the top-rated answer under this question and start working with the database.
In addtion to being the JPA reference implementation, EclipseLink also offers:
EclipseLink MOXy
EclipseLink is a component for mapping Java objects (included JPA entities) to/from XML. It conforms to the JAXB 2.X (JSR-222) specifications with useful extensions such as: XPath based mapping, externalized metadata.
EclipseLink SDO
SDO stands for Service Data Objects (JSR-235, EclipseLink is the reference implementation). Data is represented as a DataObject with generic get/set methods (such as set("first-name", "Jane")). The metadata is normally provided as an XML schema, and there are several helpers for acting on the data including conversion to/from XML.
EclipseLink DBWS
Is used to create a Web Service as a means of accessing your relational data.