These are chat archives for hibernate/hibernate-orm

13th
Nov 2017
Steve Ebersole
@sebersole
Nov 13 2017 14:57
@Redmancometh um, going to need a tad more info than that. converters work just fine, unless you found some edge case
so how does it not work? exception? just no conversion?
Eric Turley
@ericjturley
Nov 13 2017 21:25
I've implemented a Spring Boot + Hibernate 5.2 + Hazelcast 2nd-level cache.
I'd like to have it turned off and on based on a Spring Profile.
But tho I've moved the relevant properties to a application-second_level_cache.properties file, without the profile active, I get this error:
NoCacheRegionFactoryAvailableException: Second-level cache is used in the application
If I comment out the hibernate @Cache annotation on my entity, the problem goes away, but of course, that's not something I can toggle with a profile.
Is there a way to do what I'm trying to do?
Or - is there a better strategy to using the 2nd-level cache in JUnit tests?
Steve Ebersole
@sebersole
Nov 13 2017 22:49
@ericjturley Isn't this more of a question about Spring?
as far as Hiberate and caching and tests... in the Hibernate tests we have the tests tell us whether they want caching enabled and adjust the settings accordingly b4 building the SF
Eric Turley
@ericjturley
Nov 13 2017 23:08
@sebersole - I'm not sure.
I have to add the hibernate @Cache annotation to the entity, and that's hard-coded.
In configuration, I can use a hibernate property to turn off caching - but then hibernate throws an exception.
So I'm thinking there's a way to tell hibernate to stop requiring a cache during tests?
Steve Ebersole
@sebersole
Nov 13 2017 23:08
yep
Eric Turley
@ericjturley
Nov 13 2017 23:08
How do you "have the tests tell us..." ?
Steve Ebersole
@sebersole
Nov 13 2017 23:09
hibernate.cache.use_second_level_cache=false
does not matter if the entity is annotated
if you disable caching ^^, caching will not be used
again trhough I have zero idea how you do that in Speing
Spring
Eric Turley
@ericjturley
Nov 13 2017 23:12
It's easy
application.properties:
spring.jpa.properties.hibernate.cache.use_second_level_cache=false
Steve Ebersole
@sebersole
Nov 13 2017 23:13
if you say so
;)
Eric Turley
@ericjturley
Nov 13 2017 23:14
Hehe.
It's no problem, but then, it seems it keeps trying to recreate my Hazelcast 2nd-level cache instance:
Caused by: com.hazelcast.core.DuplicateInstanceNameException: HazelcastInstance with name 'meetup_api_hazelcast_cluster' already exists!
Steve Ebersole
@sebersole
Nov 13 2017 23:14
Spring simplifies somethings and complicates others
Eric Turley
@ericjturley
Nov 13 2017 23:14
Well, that's pretty obviously a Hazelcast config problem, I guess.
Steve Ebersole
@sebersole
Nov 13 2017 23:14
then I would guess that setting is not seen
Eric Turley
@ericjturley
Nov 13 2017 23:14
But I thought maybe I was "doing it wrong" anyway
Steve Ebersole
@sebersole
Nov 13 2017 23:14
or Hibernate would not try to instantiate it
(assuming that exception comes back to Hibernate trying to create your factory)
the stack trace should show that
Eric Turley
@ericjturley
Nov 13 2017 23:16
That makes some sense, tho that is a well-known property, and I've seen it work when running the app (as opposed to tests).
Still - I'll explore that.
I guess I was hoping someone would say - hey, here's a best-practices method of isolating your caching during spring boot tests
Steve Ebersole
@sebersole
Nov 13 2017 23:17
i'd set a break point in SessionFactoryImpl#<init> and see what the value of that setting is
Eric Turley
@ericjturley
Nov 13 2017 23:17
That I was just taking the wrong approach.
Steve Ebersole
@sebersole
Nov 13 2017 23:17
isolating how?
Eric Turley
@ericjturley
Nov 13 2017 23:18
Well - my problems seem to be solvable maybe a couple ways:
  1. Re-use the hazelcast instance
  2. Turn off caching during tests (possibly a temp solution)
So - isolating maybe either of those ways.
Or heck, even:
  1. Destroy the old hazelcast instance and rebuild it for every test (ugh)
Steve Ebersole
@sebersole
Nov 13 2017 23:19
well you should be able to turn off caching usig that setting
Eric Turley
@ericjturley
Nov 13 2017 23:19
/agree
Steve Ebersole
@sebersole
Nov 13 2017 23:19
what is the scope for the SF
?
do you keep the same SF around for all tests?
in terms of reusing cache instances, both the Infinispan and Ehcache integrations show how to do that
Eric Turley
@ericjturley
Nov 13 2017 23:21
So - my code is not accessing a session factory directly at all.
Steve Ebersole
@sebersole
Nov 13 2017 23:21
thats not really relevant ;)
its still tere
s/tere/there
Eric Turley
@ericjturley
Nov 13 2017 23:21
Ah - ok, well that just means that I don't know the answer to your question.
I dunno what Spring and Hibernate are getting up to in there.
Steve Ebersole
@sebersole
Nov 13 2017 23:22
exactly, because Spring complicates some things ;)
Eric Turley
@ericjturley
Nov 13 2017 23:22
indeed.
But tell me this: SessionFactoryImpl is a big class - where do you suggest the breakpoint?
oh, init
nm
Steve Ebersole
@sebersole
Nov 13 2017 23:24
second level caching is a "service", initiated by org.hibernate.cache.internal.RegionFactoryInitiator
you can also put a break point in there to see everytime that factory is being initiated
does your factiry implement org.hibernate.cache.spi.RegionFactory#stop?
also you could enable logging on either of those 2
or both
I need to run
good luck
Eric Turley
@ericjturley
Nov 13 2017 23:26
First - I'm seeing in the debugger that SessionFactoryImpl is receving an Options object with 2nd level cache disabled.
Thanks.