Maven dependencies regarding javax.persistence JAR? - java

I am using Spring 3 and Hibernate 4 JPA. I am confused regarding javax.persistence JAR. I found below two Maven dependencies on Google. Please tell me which one is required in below two dependencies?
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>

The first of those javax.persistence.persistence-api is the API Jar, which defines vendor-neutral interfaces which your application should be working with.
The second is the EclipseLink implementation of that API.
It is possible to remove references to the first javax.persistence dependency and just use the EclipseLink jar. However there is a good reason not to.
Writing and compiling your code against the vendor-neutral javax.persistence API ensures that your application code is portable to different persistence providers. For instance if you wished to switch to Hibernate, then you could put that in your pom.xml and remove the org.eclipse dependency, without changing any of your application code.
However, there's an extra little detail you should change. To ensure that your application can switch between persistence providers, the 'implementation' dependency should only be used at runtime. Otherwise, vendor-specific code could easily make its way into your codebase. Add the following to your org.eclipse dependency and see whether your application compiles.
<scope>runtime</scope>
As a result of that, you may find that your application has EclipseLink-specific code in it. This means that you could not change persistence provider without changing your codebase.
Whether that's a problem is up to you. ;)

<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
Which is the lastest one and compact with hibernate 4. Also latest version of hibernate support jpa 2.1.0 please check this link

You dont need to include that dependency explicitly, it is in Hibernate pom and will be added transitively

Related

Better way of using spring boot starters

I found two way of adding dependencies for spring boot rest service application.
Method 1 :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
Method 2:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Both method given above does the same job? Any difference in performance?
Thanks in advance
The difference between these methods is that spring-boot-starter-web contains more dependencies than just spring-boot-starter and spring-web.
For the version 1.5.8.RELEASE it will be:
spring-boot-starter
spring-boot-starter-tomcat
hibernate-validator
jackson-databind
spring-web
spring-webmvc
All other stuff depends on your requirements. For instance, if you're developing commercial product you must check all included transitive dependencies for their licenses.
The general advice is to use only features you need. Don't forget that you still can depend on top level artifact excluding not required parts using Maven feature.
At for the performance boost, basically it should not be that much. The difference is only if the Spring (with top-level artifact dependency) will load and auto configure some features which are not practically used in your code (during the classpath scanning). The startup time could be slightly increased by the same reason.
Hope it helps!
Obviously second approach is better i.e. using springboot starter pom.
Reasons I say that for are as follows:-
It allows zero configuration or auto configuration i.e. most of the web related settings would be given to you by default. e.g. by default tomcat server would be integrated, springboot dependencies would be added for you, automatic registration of converter and other web related dependencies etc. See this link.
You could take advantage of easy override i.e. if tomorrow you want to use jetty in place of tomcat just add the jetty dependency and it's configurations and now you could use jetty.
Your pom.xml would be neater and more readable as less no. of dependencies are put inside it and picked from starter poms.
Easy compatibility management. By default spring-boot picks up the version of starter parent. Hence, you could rest assured that all compatible dependencies would be downloaded as part of mvn dependencies and if you specifically want to upgrade any of those you could. But this gives advantage of upgrading to compatible dependencies by just changing the version of springboot starter parent(Note: You could use dependency management as well in place of starter parent pom. See this link).
Performance wise there would be a trade-off as springboot by default downloads more dependencies than minimum required initially. But over the time as application starts becoming mature most of these dependencies are used anyways.

Minimum set of libraries required to use Jackrabbit JCR implementation?

I am planning to user Jackrabbit for developing an online document library.
To develop simple POCs, i have put the jackrabbit-standalone.jar inside my class path and everything works fine.
But on opening the jackrabbit-standalone.jar, i found out that it's a web project in itself.
I copied all the jars from jackrabbit-standalone.jar/WEB-INF/lib and kept in my class path and my project again works fine.
My concern here is that I don't want to keep any extra jars in my project. So my question is :
What are the minimal jars which are required to interact with
Jackrabbit repository?
What is the best way of using jackrabbit in a web project, as per enterprise standards. Is it using standalone jar in the class path or using only the required jars?
I won't ask why you want cut out unnecessary jars for a POC.
Do you use maven? If so, you just add jackrabbit-core and it will pull down dependencies.
If you require the JCR API you'll also need jackrabbit-spi2jcr.
Otherwise, this is what we end up with (version 2.6.4):
commons-collections-3.2.1.jar
commons-dbcp-1.3.jar
commons-pool-1.5.4.jar
concurrent-1.3.4.jar
jackrabbit-api-2.6.4.jar
jackrabbit-core-2.6.4.jar
jackrabbit-jcr-commons-2.6.4.jar
jackrabbit-spi-2.6.4.jar
jackrabbit-spi-commons-2.6.4.jar
jackrabbit-spi2jcr-2.6.4.jar
jcl-over-slf4j-1.6.4.jar
jcr-2.0.jar
log4j-1.2.16.jar
lucene-core-3.6.0.jar
slf4j-api-1.6.4.jar
slf4j-log4j12-1.6.4.jar
tika-core-1.3.jar
You can dispense with the logging jars if not needed. Not sure if you can get rid of lucene-core as I believe it's used internally.
Regarding how to use jackrabbit, that's entirely up to you. You can use it as standalone server or, like us, as your persistence layer. We use the JCR api.
you can use maven or gradle to manage dependencies for you.
If you are using maven, you can find out the dependency tree with command :
mvn dependency:tree
and review the relations between artifacts.
And you can exclude parts you don't want with exclude expressions:
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>

Eclipse-Maven Complex Project Dependency (ApacheJena)

I'm fairly new to the Eclipse and Maven2 worlds. I'm struggling to comprehend how to add a Maven project dependency on Apache Jena in a simple way. Specifically, I'd like to add a dependency such as
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena</artifactId>
<version>${jena.version}</version>
</dependency>
And this would automatically pull in the modules(eg. jena-arq, jena-core, etc). However, adding this dependency results in a Missing artifact org.apache.jena:jena:jar:2.11.1 error. If I add <type>pom</type> to the dependency the error is gone but I do not get the jars in my project.
In any event, as I understand it, POM is more suited to project <--modules dependencies and what I'm really looking for is project --> lib archive dependencies.
How do I establish such a relationship? I considered simply replicating the dependency for each module in Jena since it's using a property anyway. However, it is possible, and Jena is a prime example, that not all modules in a project share the same version. For example jena-core is on 2.11.1 where jena-tdb is on 1.0.1 however jena-2.11.1 encompasses jena-tdb.
Thanks
See http://jena.apache.org/download/maven.html for details.
In brief:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>2.11.1</version> <!-- Set version -->
</dependency>
Note that it is type pom.
there is not a easy way do this.
you must define every dependency jar with special version.

Logger dependencies in maven project

In my project, i am using :
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
I can not remove it, because a lot of other dependencies use it.
App is working with LDAP,so ecently i have add:
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<version>1.5.5</version>
</dependency>
Which is depends from:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.2</version>
</dependency>
And now i have a lot of errors:
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:225)
Can you please help me?
Yep, I see this question
You could:
Update your version to 1.5.7 which is the latest 1.x version. It depends on slf4j-log4j12:1.5.10, so this unlikely will help.
Consider using apacheds-all:2.0.0-M15. It depends on slf4j-log4j12:1.7.5 so if this version suits you, it should resolve this problem.
UPDATE
Some other ideas:
Decouple ApacheDS from Spring
or Disable logging for the problematic packages which use the old 1.5.x bridge
or Remove this bridge (by excluding a dependency) and (optionally) add log4j configuration to see log4j logs (never tried having them both!).
Maven should be picking the latest version, but you could try adding a dependency management section, to explicitly specify which version of slf4j you want. Probably picking the most recent version out of all your various dependencies will be fine (1.7.2 in this case).
Alternatively, I've come across this issue when deploying an application into jboss, because it bundles an old version of slf4j, which takes precedence over the version in my application. You can check this by running your application (or jboss or whatever) with the -verbose:class jvm parameter, it will log out where each class is being loaded from. This would tell you if it's being loaded from the jar in your application, or something in your environment.

What are the Spring Hibernate Integration jars really required

I haven't yet found an answer to this question which is bugging me for long. I am trying to integrate Hibernate (3.6.7) with Spring (1.2.8). In order to do so i have to get a bunch of jars just to get it running. Isn't there a more cleaner of way of getting this done. The jars i am using rather forced to use are as below:
spring-1.2.8.jar
commons-logging-1.0.4.jar
hibernate-3.6.7.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
dom4j-1.6.1.jar
slf4j-api-1.6.1.jar
javassist-3.12.0.GA.jar
Is there no leaner way? The big list of dependent jars could potentially cause conflict during deployment to my appserver in the future. So its making me rethink about spring-hibernate integration. Is there a way to reduce this dependency list. My issue is not related to management of jars as maven is already being used, it more to do with the usage.
This answer was posted before the OP mentioned that he was using Maven. The question seems to be asking how he can use code without including it in his project. Given that there is no answer to that question I'll answer assuming he wants a better way of managing the dependencies that he needs.
The leaner way to do this is to use a dependency management tool such as maven. This allows you to define your project's dependencies in an xml file.
The dependencies you specify will also have dependencies and so on. These are transient dependencies and are very hard to manage without an automated tool.
This is also the best way to ensure that you only have the jars you require.
The dependencies you require are:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
and:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>

Categories

Resources