Using Java Configuration with auditing in Spring Data JPA - java

Java configuration was introduced in version 1.2.0 of Spring Data, but I can't figure out how the java configuration for <jpa:auditing> should look like. I couldn't find any examples in the docs, neither did I figure it out by looking at the Spring Data JPA Source.
I'm suspecting it's not possible to translate <jpa:auditing> into java configuration, but as I couldn't find a Jira for the possibly missing feature, I'm unsure. Does anyone know if I still have to use XML configuration if I use Spring Data JPA with auditing?

EDIT: This feature is available as of version 1.5 M1 of Spring Data. See the ticket created by Alex Blomskøld for details.
Activating auditing is currently not supported by the JavaConfig means we introduced in 1.2.0. As we're planning to generally overhaul the auditing infrastructure anyway, would you mind filing a ticket against Spring Data JPA to capture that aspect of the story?

Related

Is there an easy way to map entities to Spring boot + hibernate via reverse engineering or is reverse engineering bad?

At my company, we're currently rebuilding our core application, and we're considering going with Spring Boot as opposed to just Java-Web, JAX-RS, and Weblogic.
We also built a database lib using hibernate which we use on a lot of our services, but we want to rebuild that too using Spring boot.
Now, what I desperately need is some sort of reverse engineering tool to help with this spring boot + hibernate migration. I know a question like this has been asked: questions on spring boot + hibernate and the answer given was, use a generic DAO.
But I'm working with more than a hundred tables!
Perhaps I'm looking at this the wrong way. Maybe I don't need reverse engineering to handle this massive work. In which case, I need some advice.
Thanks guys!
I already had the same experience. you can managed to generated a reverse engineered annotation based version of your database using hibernate-tools.
to use hibernate-tools you need to find the stable version of the hibernate plugin at http://www.jboss.org/tools/download. find more instruction at:
How to install Hibernate Tools in Eclipse?
Hibernate Tools in Spring Tool Suite 3.6.1
for further information and instruction on how to get to your aim, I propose you to have look at the following links:
http://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/
How to generate domain objects with annotations using hibernate tools
https://www.youtube.com/watch?v=IU7cwWMDdjU
Notice that once you manage to do a reverse engineering against your DB, hibernate-tools does not offer a configuration with spring boot and you need to provide it in you project.

How to migrate spring annotation-based Hibernate code to Java EE

First of all: here is my code: https://github.com/s1ddok/todosapp
I'm learning java technologies. I forked a demo project on github and for now my goal is to add login (user specific todos) and hibernate mysql stuff. I successfully done it for -spring version. Now I want to do the same stuff for java ee.
How do I migrate annotation based hibernate code (Entities and config) to java ee? Is it possible to simply reuse them? I heard that you have to use xml config with Java EE, is it true?
My requirement is to use same front-end (backbone) and same database for both -spring and -javaee. This is my goal. I have to implement same-functionality REST service with spring and javaee.
I'm completely stuck with that.
With JavaEE you do not have to use much XML configs (in comparison with the old J2EE), but you can do most things with annotations.
Regarding database access you can still use Hibernate (JPA), since JPA is part of the JavaEE spec. The Json annotations like com.fasterxml.jackson.annotation.JsonIdentityInfo are not part of JavaEE spec (yet), so you might have to use JAXB instead.
Regarding REST you want to have a look at JAX-RS. The annotations are different in comparison to Spring (#ApplicationPath, #Path, #GET, ...), but you should be able to achieve the same result for you application.
For security (login) you have to look at application server specific options, since this be will standarized only in JavaEE 8 (JSR 375).

Hibernate integration on a Spring web application

I have been following this tutorial on the Springsource website in order to have basic knowledge of Spring. Everything went good.
Now, I would like to integrate Hibernate to this little application I wrote following this tutorial. I found documentation on different websites (including hibernate's website) but I still have a few questions before starting.
I read some stuff about JPA and I can use it as an abstraction layer on top of hibernate but I don't really understand what for.
In addition, I read somewhere that there is two ways to use hibernate, the first one is annotations and the second one is using javax.persistance, I am right?
Is there some recent documentation about how to use hibernate in an existing spring web application, as well as the different ways to implement it?
JPA is a specification, hibernate can be considered as a implementation of the JPA spec.
You can use either annotation for mapping file with hibernate.
The following tutorials are better:
Hibernate Tutorial Vaannila
Hibernate Tutorial Mkyong
JPA is a standard, Hibernate is an implementation, but has other/additional functionality.
The Spring Reference manual's section on ORM integration covers Hibernate. There are also scores of tutorials and demos, like here, but there are a bunch of other ones, and more recent ones.

Integrating JackSon for JSON View with Spring 2.5

We are using Spring 2.5 and spring-json for JSON support. We have the below configuration in views.xml
<bean name="jsonView" class="org.springframework.web.servlet.view.json.JsonView"/>
Now, we have learnt that Spring 3.x uses JackSon API internally for JSON support. My question is how can we override the default implementation of Spring 2.5 to use JackSon - The way Spring 3.x begins.
Note: We don't want to migrate my Spring version, but, want Spring 2.5 to use this JackSon API instead of Spring-Json
Is it possible to replace Spring's JSON support without breaking it ?
Unfortunately, Spring's own documentation states that Spring-json is "deeply" a component of the existing Spring 2.5 framework.
See : http://spring-json.sourceforge.net/
That said - removing the dependencies on spring-json, adding your own JSON parser, and rebuilding spring can be done. I assume this will require a lot of work given that spring-json is a major component of the whole Spring MVC suite.
An alternative : Building a Facade
In addition, I don't know of any Java EE specification for Json libraries which implies that there is a good chance that all internal Spring json dependencies are specific to the APIs defined by Spring-json [compare this, for example, with JPA, which is generically defined by Java EE, so that it is easy to replace many a DAO framework].
Generally, you can package any sort of JSon library as a Spring component that will be available in the application context. Now - if you reimplement the necessary interfaces using the facade pattern, using Jackson under the hood, your version of Spring 2.5 should work the same. Alternatively, you could intercept Json related calls of interest using Spring's aspect oriented injection libraries, and reroute them as necessary.
Again, however, these are all advanced tasks - they would be excellent learning projects but I'm not sure that the time investment would really pay off if this is a production application.
http://www.javaworld.com/javaworld/jw-02-2008/jw-02-springcomponents.html

Hibernate implementation of JPA

I'm wanting using JPA in ear project. Development project must be started ASAP so I have not a lot of time to research and investigate. Could you say please JPA API is restricted functionality of Hibernate or no. At this moment I'm using Hibernate directly. For example in future I'm planing to use hibernate-search and maybe hibernare-validate and -shard. Can I be sure that in future I will not have problem with using this.
And one more example - can I use HAR archive and JPA together.
Why JPA? For project will available RESTful service (jersey or resteassy implementation). And as I looked in much case using JPA for this. I'm a newbie in this so it's only my IMHO. May be i mistakes.
Thanks a lot.
Best regards
Artem
JPA is a subset of hibernate, but you're not limited to it. If you need a hibernate specific feature, you can generally use it at the cost of being tied to hibernate. For example, we've mixed in hibernate annotations with JPA ones, including the validater ones, without trouble.
JPA in theory lets you change the persistance provider later.
Sticking to only JPA compatible configuration can cause more trouble that is solved by the dubious promise of seamlessly swapping providers however.

Categories

Resources