Generator-jhipster: Upgrade to Hibernate 5.2 and Ehcache 3

Created on 22 Sep 2016  Â·  46Comments  Â·  Source: jhipster/generator-jhipster

This is a feature request.

A pull request will follow since we are working on it.

We would like to upgrade JHipster to use Hibernate 5.2 and Ehcache 3.

This requires a bit of work. We have identified the following tasks:

  • Upgrade to Hibernate 5.2
  • Use jackson-datatype-hibernate to 5
  • Add hibernate JCache support
  • Code liquibase-hibernate52
  • Update to Ehcache 3
  • Connect Hibernate to Ehcache 3 using JCache
  • Connect Spring to Ehcache 3 using JCache
  • Code Codehale Metrics support to Ehcache 3

If someone has partially done some of these tasks, please communicate with me.

If you think something was forgotten, please tell me.

area

Most helpful comment

Yep. Next step is the PR to jhipster. I have all the working code locally, I "just" need to move it in the generator.

All 46 comments

Thanks @henri-tremblay !
For Hibernate 5 support in Liquibase, have a look at https://github.com/liquibase/liquibase-hibernate/issues/96 - there are already people working on it, but it's not finished yet, and this has been stalled for a long time

Support for Hibernate 5.2 has been pushed to the liquibase/liquibase-hibernate master branch. If you could do some testing with it and let me know how it goes I would greatly appreciate it.

For hibernate, I guess we should use Spring Boot 1.4 version which is 5.0 (from dependency management)

I pushed a new change to liquibase-hibernate master to depend on Hibernate 5.0.10. Just a small change to the hibernate APIs I was calling and my tests are still passing.

@nvoxland Will test. So your stuff now works on Hibernate 5.0 and 5.2? Am I getting it right?

@cbornet What do you mean? JHipster seems to use Spring Boot 1.4.1 already

Yes, it should work with any version of hibernate 5.0 and above.

I mean that we should use the same hibernate version as SB unless we have a good reason not to do so and that version is 5.0

Yes we should have the SB version, unless we have a good reason to change it, that's one of the project policies at http://jhipster.github.io/policies/

Sorry, for some reason the last comments went lost in my inbox. What is SB? (newbie question I guess)

SB stands for "Spring Boot"

Regards!

Ok... This is a problem I must say. Because right now my implementation is using JCache. And Hibernate has started to support JCache in 5.2. We are also working on a JCache metrics connector. Not using JCache would be a bit more complicated.

Well, maybe this could fit in our definition of "a good reason to change it" :-)
Our biggest issue is that this needs to work with Spring Data JPA, but I have no reason to think this would cause any issue.
And anyway, if we just wait a little bit, Spring Boot will probably update to Hibernate 5.2. So that shouldn't be a blocker issue.
@henri-tremblay unless this causes any issue with Spring Data (which I doubt, and which we could probably solve anyway), let's go for Hibernate 5.2

I've been running in this version since the beginning of the week and had no issue so far.

However, about liquibase-hibernate5, I had no issues running the application. However, the liquibase-maven-plugin doesn't work yet (liquibase:diff).

A little summary for @nvoxland

  • I've added these dependencies to the plugin.
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-core</artifactId>
                        <version>${hibernate.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-validator</artifactId>
                        <version>${hibernate.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.el</groupId>
                        <artifactId>el-api</artifactId>
                        <version>2.2</version>
                    </dependency>
  • I need to update the strategy setup of the plugin. There is now an implicit and physical strategy in hibernate
  • Then it is still failing about an error on the second level cache that can't be loaded. I need to investigate.

@henri-tremblay if you want to have a good test with the "liquibase:diff" goal:

-> when you run "liquibase:diff", you should only get that new field in the changelog.

Ok. Thanks. It should fails if I use H2 Disk? (currently, it does)

_Probably_ not :-)
I haven't used it for a long time (I use MySQL), but H2 should have a port opened (I remember configuring this), and the Maven goal can then use it to connect to the database and do the diff.

Indeed, it works with a normal generation (without me modification). If fails if I use liquibase 3.5.2 though. Some details at liquibase/liquibase-hibernate#96

I've done a pull request on liquibase/liquibase-hibernate#96. Everything seems to work fine. I still need to do the MySQL test but we are close to the end.

Great news! I'll do a specific release when this is ready

Liquibase-hibernate5 v3.6 has been released

Yep. Next step is the PR to jhipster. I have all the working code locally, I "just" need to move it in the generator.

Awesome

Thanks & regards,
Deepu

On 25 Oct 2016 02:10, "Nathan Voxland" [email protected] wrote:

Liquibase-hibernate5 v3.6 has been released

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/4195#issuecomment-255859513,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABDlF08eWJz7AYQOuEjZTBc041FlxrLFks5q3Re0gaJpZM4KEZkZ
.

@henri-tremblay @nvoxland it looks like you are pretty close to have something fully working. My idea is that this is such a big update that it needs to be its own release, so when you have the PR ready we need to synchronize.

My goal is to have a release with all your changes in one place, and have the correct release notes (I'll need your help), and of course go through the usual Twitter, etc to have everybody knows about this upgrade.

Sure. I'm stuck on something else but starting next week, my free time
should be dedicated to it.

On 28 October 2016 at 10:48, Julien Dubois [email protected] wrote:

@henri-tremblay https://github.com/henri-tremblay @nvoxland
https://github.com/nvoxland it looks like you are pretty close to have
something fully working. My idea is that this is such a big update that it
needs to be its own release, so when you have the PR ready we need to
synchronize.

My goal is to have a release with all your changes in one place, and have
the correct release notes (I'll need your help), and of course go through
the usual Twitter, etc to have everybody knows about this upgrade.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/4195#issuecomment-256940487,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABKRM7WbShKcl0LFsCQ2pJbPwe_6UyBCks5q4gtPgaJpZM4KEZkZ
.

@nkolosnjaji can caffeine be used as second level cache for hibernate? The spring boot link seems to cover only spring cache abstraction

Yes. I will provide a patch using Ehcache... because I'm kinda working on Ehcache. But the implementation including metrics is fully JCache compliant. So switching to another framework will be much more easier.

Should be able to work on it next week during Devoxx.

I'm a big believer in those doing the work should get the credit, so @henri-tremblay advocating Ehcache in the patch / documentation is a nice reward. Mentioning other providers in the documentation would be reasonable, but perhaps with less emphasis.

If the generator supported multiple providers, changed defaults, etc. that could be a different discussion. But I wouldn't want to detract from @henri-tremblay effort by promoting Caffeine.

Thanks @henri-tremblay and @nkolosnjaji.

Thanks @ben-manes that is really fair from you!

Thanks guys. BTW, if you want to see the generated result, it is now an Ehcache sample. That's what I need to move to the generator.

OMG, you mean some of my code is now part of the official ehcache sample? I'm so proud!!!!!!

:-)

@henri-tremblay I tried to build the fullstack example, but I get the following error:

[INFO] --- maven-processor-plugin:2.2.4:process (process) @ demo ---
[ERROR] diagnostic: /Users/mraible/dev/ehcache3-samples/fullstack/src/main/java/org/terracotta/demo/config/jcache/SpringCacheRegionFactory.java:3: error: package org.hibernate.boot.spi does not exist
import org.hibernate.boot.spi.SessionFactoryOptions;
                             ^
[ERROR] diagnostic: /Users/mraible/dev/ehcache3-samples/fullstack/src/main/java/org/terracotta/demo/config/jcache/SpringCacheRegionFactory.java:5: error: package org.hibernate.cache.jcache does not exist
import org.hibernate.cache.jcache.JCacheRegionFactory;
                                 ^
[ERROR] diagnostic: /Users/mraible/dev/ehcache3-samples/fullstack/src/main/java/org/terracotta/demo/config/jcache/SpringCacheRegionFactory.java:15: error: cannot find symbol
public class SpringCacheRegionFactory extends JCacheRegionFactory {
                                              ^
  symbol: class JCacheRegionFactory
[ERROR] diagnostic: /Users/mraible/dev/ehcache3-samples/fullstack/src/main/java/org/terracotta/demo/config/jcache/SpringCacheRegionFactory.java:18: error: cannot find symbol
    public void start(SessionFactoryOptions options, Properties properties) throws CacheException {
                      ^
  symbol:   class SessionFactoryOptions
  location: class org.terracotta.demo.config.jcache.SpringCacheRegionFactory
[ERROR] diagnostic: /Users/mraible/dev/ehcache3-samples/fullstack/src/main/java/org/terracotta/demo/config/JCacheGaugeSet.java:19: error: package javax.cache.management does not exist
import javax.cache.management.CacheStatisticsMXBean;
                             ^
[ERROR] diagnostic: /Users/mraible/dev/ehcache3-samples/fullstack/src/main/java/org/terracotta/demo/service/WeatherService.java:19: error: package javax.cache.annotation does not exist
import javax.cache.annotation.CacheResult;
                             ^
[ERROR] diagnostic: /Users/mraible/dev/ehcache3-samples/fullstack/src/main/java/org/terracotta/demo/service/WeatherService.java:43: error: cannot find symbol
    @CacheResult(cacheName = "weatherReports")
     ^
  symbol:   class CacheResult
  location: class org.terracotta.demo.service.WeatherService
[ERROR] error on execute: error during compilation

My environment:

Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T05:57:37-06:00)
Maven home: /opt/tools/maven
Java version: 1.8.0_65, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"

Actually, this happens when I run yo jhipster on the project, which is likely expected. If I just try to build using ./mvnw, I get:

[ERROR] Failed to execute goal on project fullstack: Could not resolve dependencies for project 
org.ehcache.sample:fullstack:war:1.0.0-SNAPSHOT: The following artifacts could not be resolved: 
org.terracotta.management:management-entity-client:jar:5.0.6.beta5, 
org.terracotta.management:management-model:jar:5.0.7.beta: Failure to find 
org.terracotta.management:management-entity-client:jar:5.0.6.beta5 in 
https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be 
reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

Oh! That's interesting. I guess I need to add Terracotta repositories. Let
me see.

On 1 November 2016 at 14:01, Matt Raible [email protected] wrote:

Actually, this happens when I run yo jhipster on the project, which is
likely expected. If I just try to build using ./mvnw, I get:

[ERROR] Failed to execute goal on project fullstack: Could not resolve dependencies for project
org.ehcache.sample:fullstack:war:1.0.0-SNAPSHOT: The following artifacts could not be resolved:
org.terracotta.management:management-entity-client:jar:5.0.6.beta5,
org.terracotta.management:management-model:jar:5.0.7.beta: Failure to find
org.terracotta.management:management-entity-client:jar:5.0.6.beta5 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be
reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/jhipster/generator-jhipster/issues/4195#issuecomment-257642642,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABKRM7vZQP39Yg65cyvp-HAVDN9UzOynks5q536OgaJpZM4KEZkZ
.

Can you add this at the end of your pom?

    <repositories>
        <repository>
            <id>terracotta</id>
            <url>http://repo.terracotta.org/maven2</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

@mraible I've removed the bad dependencies. So if you pull the new code, it should work nicely without the Terracotta repo. Thanks @anthonydahanne who did the code sample with me and just approved the PR containing the fix :-)

@henri-tremblay Adding the repositories works, as does pulling the latest code.

I'm interested in this sample because it uses EhCache and we, at Stormpath, have had an issue with the caching setup in a JHipster application. It seems we have to add entries in ehcache.xml for things to work.

This seems strange since I took your example, commented out all the JHipster-specific entries and it works just fine. However, when I integrate Stormpath, it blows up. Note that if I create a JHipster app with Hazelcast, Stormpath caching doesn't need any additional configuration.

@henri-tremblay I just had a look at the ehcache sample and really liked it. Thanks a lot for working on this.

I also noticed that there is a "clustered" config with a docker config for an off-heap server. It would be very interesting for https://github.com/jhipster/generator-jhipster/issues/3621 which was an idea we had of adding a scalable cache for requests that passed through our Zuul Gateway.

Do you think this could work ?

@PierreBesson good catch :-)
The clustered cache configuration can be used to connect your client caches to a terracotta server (that is using offheap storage to store your cache elements).
With this demo, @henri-tremblay and I show that it is possible to start with local caching and then easily switch (changing few lines in ehcache.xml) to clustered caching : several instances of your jhipster app keeping their caches in sync using a Terracotta server (if instance1 loaded actorA, then instance2 will have it in cache via its clustered store)

Quickly browsing through #3621 I understand you wanted to try using a cache integrated with spring cache; I'd say ehcache3 is a pretty good match :-) and for scaling, yes, this use case is covered with clustered ehcache3

@anthonydahanne This looks really interesting, it would be interesting to integrate this and have an option for the clustered cache in JHipster as well.

Will support for Hibernate 5.x mean that Geometry/Spatial data type will be available in entity?
I hope this will. Thank you.

@zulfahmi we are just doing an upgrade for the moment, so nothing more. This ticket is about doing this upgrade, if you want new features please add a new ticket.

@jdubois I see, thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sdoxsee picture sdoxsee  Â·  4Comments

tomj0101 picture tomj0101  Â·  3Comments

dronavallisaikrishna picture dronavallisaikrishna  Â·  3Comments

SudharakaP picture SudharakaP  Â·  3Comments

marcelinobadin picture marcelinobadin  Â·  3Comments