difference between javax.persistence.Entity vs jakarta.persistence.Entity [duplicate] - spring

I've recently started to learn spring boot, data jpa. As I can see from this, the spring boot data jpa starter uses jakarta.persistence-api instead of javax.persistence-api:
<artifactId>spring-boot-starter-data-jpa</artifactId>
...
<dependencies>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<exclusions>
<exclusion>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</exclusion>
...
</exclusions>
</dependency>
</dependencies>
What is the differences between jakarta.persistence-api and javax.persistence-api? What is the reason of this replacement?

From Java Persistence API on Wikipedia:
The Java Persistence API (JPA), in 2019 renamed to Jakarta Persistence, is a Java application programming interface specification that describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition/Jakarta EE.
After Java EE was open sourced by Oracle and gave the rights to the Eclipse Foundation they were legally required to change the name from Java as Oracle has the rights over the Java brand. The name Jakarta was chosen by the community. You can find more information by reading Transition from Java EE to Jakarta EE and Jakarta EE - No Turning Back.

Related

Should I include the dependency spring-boot-starter into my custom spring boot starter?

If I create a custom spring boot starter module, Do I need to include the dependency spring-boot-starter ?
In the spring boot's github :
some starters add the dependency spring-boot-starter to its pom.xml (spring-boot-starter-web, spring-boot-starter-thymeleaf)
some others starters doesn't (spring-boot-starter-log4j2, spring-boot-starter-undertow, spring-boot-starter-tomcat).
Is there a reason to no adding it into the dependencies ?
If your starter depends on spring-boot-starter, any application that depends only on your starter will have all the dependencies that it needs to be a Spring Boot application. Generally speaking, this is how you want a starter to behave.
spring-boot-stater-log4j2, spring-boot-starter-undertow, and spring-boot-starter-tomcat are slightly different as they are not intended to be used on their own. The Spring Boot documentation calls them technical starters. They are intended to be used alongside an existing starter to change the underlying technology that's used. For example, if you are building a web application, you would depend on spring-boot-starter-web. This starter uses Tomcat as the embedded container by default. If you want to swap to Undertow, you'd exclude spring-boot-starter-tomcat and add a dependency on spring-boot-starter-undertow alongside your spring-boot-starter-web dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Use Undertow instead -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

Why does H2 database use Hibernate Core in Springboot application

I have a simple springboot application which uses H2 in memory db. I have used following dependency in my POM
spring-boot-starter-data-jpa
com.h2database.h2
When I start application, It automatically create Entity tables using Hibernate Dialect. I have no where mentioned about Hibernate in my POM. So why does this happening. Why Spring is using Hibernate Dialect. Do we have any option to change this dialect to some other dialect. please help.
Starter poms in the SpringBoot ecosystem bring a bag of dependencies, which have been tested and are proven to work together. It also saves you the hustle of managing the right dependencies versions.
You're using spring-boot-starter-data-jpa - which is a starter pom for JPA - the opinionated choice here is the usage of Hiberante as JPA provider.
If you look at the source of the pom file, you will see this definition:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
This is what brings hibernate to your project, although you have not explicitly declared it in your pom. The hibernate is downloaded as implicit dependency because of your spring-boot-starter-data-jpa starter pom.
Well you using "spring-boot-starter-data-jpa" and "starter" notion means that it has everythingfor it to work. If you would look to https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa/2.1.3.RELEASE , this dependency also includes hibernate-core.

Spring Boot 2 and ResourceServerProperties

We have Spring Boot Application(version 1.5.8). We tried to check if it's compatible with upcoming Spring Boot 2 release (currently it's M5).
And two classes are missing in spring-boot-autoconfigure dependency(UserInfoTokenServices and ResourceServerProperties).
Are there any replacements of them?
Thanks
Try it this. it's helped me with Oauth2 after migration to SpringBoot 2.
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
Quoting Spring Boot 2.0.0.M5 release notes
Functionality from the Spring Security OAuth project is being migrated
to core Spring Security. OAuth 2.0 client support has already been
added and additional features will be migrated in due course.
If you depend on Spring Security OAuth features that have not yet been
migrated you will need to add
org.springframework.security.oauth:spring-security-oauth2 and
configure things manually. If you only need OAuth 2.0 client support
you can use the auto-configuration provided by Spring Boot 2.0. We’re
also continuing to support Spring Boot 1.5 so older applications can
continue to use that until an upgrade path is provided.
I think you have to define oauth2 dep, like
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>

What are the recommended JSF dependencies with TomEE1.7.x?

I've been developing a JSF2.0 (I'm not really sure about the JSF version) application on TomEE 1.7.3 (JavaEE6 based).
In my Maven pom.xml, I had too many dependencies which I've copied from many examples, but I reduced them to minimum requirements. Bellow is the "dependencies" part of my pom.xml:
<dependencies>
<!-- JavaEE6 -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
<!-- /JavaEE6 -->
<!-- OmniFaces for JSF, #Eager, postback same request parameters, etc. -->
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>1.8.3</version>
</dependency>
<!-- /OmniFaces -->
<!-- glassfish faces (is it called mojarra??) -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.12</version>
<scope>runtime</scope>
</dependency>
<!-- /glassfish faces -->
<!-- some mysql connector -->
<!-- some aws sdks, s3, ec2, etc -->
<!-- some apache commons, StringUtils. etc -->
<!-- some apache velocity -->
</dependencies>
The org.glassfish#javax.faces#2.2.12 dependency can be removed as well,
but it causes html layout problem (with the bootstrap css).
Downgrading it to version 2.0.x, causes the same layout problem.
I know I can fix it, but it takes couple of hours.
What I want to ask is:
Is it good or bad idea to use glassfish faces 2.2.x within TomEE1.7.x? TomEE's description says that it only supports up to JSF 2.0, but so far, it is working almost fine (I have few problems but those do not seem relevant to this version).
Is it better to remove glassfish faces dependency and use the default MyFaces instead?
Is it even better if I choose glassfish server, instead of TomEE, in my case?
BTW, I asked another question yesterday:
JSF2.0 Some facesmessages not sent to redirected page on error handling
and I recognized that I have to clean up my project first, so it might help reduce my problems.
Thank you.
As you already said yourself, TomEE is a Java EE 6 container (and not a barebones JSP/Servlet container like Tomcat). So it has already (nearly) everything from Java EE 6 provided out the box, including JSF 2.0/2.1. Nearly, because it's actually a Java EE web profile container. So you should actually use javaee-web-api artifact ID.
Only this should be sufficient:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
As an Apache product, its bundled JSF implementation is actually MyFaces, not Mojarra.
In case you intend to use JSF 2.2, which is part of Java EE 7, you should be using TomEE 7 instead and change the version in pom.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
A milestone was released just this month, see the downloads page. Alternatives to TomEE 7 are WildFly 8+ or Payara 4+.
See also:
Our JSF wiki page - also contains JSF installation instructions and Maven coordinates (and many more useful information to get started).

spring-boot-starter-tomcat vs spring-boot-starter-web

I'm trying to learn Spring boot and I notice there are two options.
spring-boot-starter-web - which according to the docs gives support for full-stack web development, including Tomcat and web-mvc
spring-boot-starter-tomcat
Since #1 supports Tomcat why would one want to use #2?
What are the differences?
Thanks
Since #1 supports Tomcat why would one want to use #2?
spring-boot-starter-web contains spring-boot-starter-tomcat. spring-boot-starter-tomcat could potentially be used on its own if spring mvc isn't needed (contained in spring-boot-starter-web).
Here is the dependency hierarchy of spring-boot-starter-web:
What are the differences?
spring-boot-starter-web contains spring web dependencies (including spring-boot-starter-tomcat):
spring-boot-starter
jackson
spring-core
spring-mvc
spring-boot-starter-tomcat
spring-boot-starter-tomcat contains everything related to an embdedded tomcat server:
core
el
logging
websocket
What if you want to use spring mvc without the embedded tomcat server?
Just exclude it from the dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
Well a simple answer is that not all web applications are SpringMVC applications. For example if you wish to use JaxRS instead perhaps you have client applications that use RestTemplate and you like how they interact it doesn't mean you can't use spring boot or embedded tomcat
Here is an example application that uses spring-boot-starter-tomcat but not spring-boot-starter-web
Simple Jersey application in spring boot using spring-boot-starter-tomcat
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-jersey
It's also important to remember that tomcat is not the only option for an embedded servlet container in spring boot. It's also easy to get started using jetty. And having spring-boot-starter-tomcat makes it easy to exclude all as one module while if they were all just part of spring-web it would be more work to exclude the tomcat libraries to bring in spring-boot-starter-jersey instead
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
I copied this code from another SO question here.
How to configure Jetty in spring-boot (easily?)

Resources