Hibernate DuplicateMappingException when debugging using JUnit

Answered

Hoping someone can help.

My project uses Spring, JPA (hibernate provider), and Hibernate hbm.xml files to map entities and named queries (I like having the mapping externalized). The Spring config is annotation driven. This application starts and runs fine. It also tests fine. All tests run and pass in the Maven runner using the ‘test’ goal. All tests run and pass using the JUnit runner.

The issue is when debugging tests. If I debug using the JUnit Runner, I get the following error:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate query mapping <my-named-query>

I get it when debugging a single test method, a single test class, or all the test classes. But it does not happen when I simply run a test or I run multiple tests. It only happens when debugging. My tests start the Spring context via annotations on the test class.

@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {ApplicationConfiguration.class})

Any thoughts? Thanks in advance.

1
10 comments
Avatar
Permanently deleted user

Oddly enough... I DO NOT get the issue when I "Debug with JRebel". So odd.

0
Avatar
Yaroslav Bedrov

Hello Michael,

Is it possible to provide project example for investigation?

0
Avatar
Permanently deleted user

Hi. Thanks for the help. Here is the project example. 

https://github.com/michaelajr/debugger-bug

I also included the run configs. Of note, the JUnit Run/Debug config. Works when run, does not work when debugging. Also, I can externally run:

$ mvn -Dmaven.surefire.debug test

And then attach the remote debugger... and it works!

So the issue seems to be debugging using the JUnit Run/Debug config. 

Thanks for looking into this!

M

 

0
Avatar
Yaroslav Bedrov

Michael,

Please disable debugger agent in "File | Settings | Build, Execution, Deployment | Debugger | Async Stacktraces"

 

0
Avatar
Permanently deleted user

Wow. That did it. THANK YOU. What was that agent providing? Is there a reason I would want to use it? Thanks so much for the help.

0
Avatar
Yaroslav Bedrov

Michael,

It was added to debug asynchronous code: https://www.jetbrains.com/help/idea/tutorial-java-debugging-deep-dive.html#async_stacktraces

It might result in code duplication which caused the error.

1
Avatar
Permanently deleted user

Interesting. Ok. Thanks again.

0
Avatar
Permanently deleted user

Should I open an issue for this?

0

I was able to reproduce it on java 9. Interestingly, it works well with java 10. Will investigate more.

0

This is a bug https://bugs.openjdk.java.net/browse/JDK-8185540 in jdk 9, it is fixed in jdk 10. Please use java 10 or disable the instrumenting agent.

0

Please sign in to leave a comment.