question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unit Test failire: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread

See original GitHub issue
Overview of the issue

I am using JHipster Generator v4.0.7 and I create an entity like that:

entity Country {
	id Long, 
	name String required
}

entity Zone {
	id Long, 
	name String required 
}

relationship OneToMany {

  Zone to Country{zone(name) required},
}

When I generate the code, JHipster generator generate failed unit test. I have this stacktrace:

 -------------------------------------------------------------------------------
Test set: xxx.yyy.zzz.CountryResourceIntTest
-------------------------------------------------------------------------------
Tests run: 11, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.134 sec <<< FAILURE! - in xxx.yyy.zzz.web.rest.CountryResourceIntTest
equalsVerifier(xxx.yyy.zzz.web.rest.CountryResourceIntTest)  Time elapsed: 0.054 sec  <<< ERROR!
javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:282)
	at com.sun.proxy.$Proxy165.persist(Unknown Source)
	at fr.accs.advalorem.web.rest.CountryResourceIntTest.createEntity(CountryResourceIntTest.java:101)
	at xxx.yyy.zzz.web.rest.CountryResourceIntTest.initTest(CountryResourceIntTest.java:115)

It seems that equalsVerifier method should be @Transactional because it call the @Before method

Suggest a Fix

Replace

    @Test
    public void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(Country.class);
    }

By

    @Test
    @Transactional
    public void equalsVerifier() throws Exception {
        TestUtil.equalsVerifier(Country.class);
    }
JHipster Version(s)

JHipster generator v4.0.7

Entity configuration(s) entityName.json files generated in the .jhipster directory

Country.json:

{
    "fluentMethods": true,
    "relationships": [
        {
            "relationshipType": "many-to-one",
            "relationshipValidateRules": "required",
            "relationshipName": "zone",
            "otherEntityName": "zone",
            "otherEntityField": "name"
        }
    ],
    "fields": [
        {
            "fieldName": "name",
            "fieldType": "String",
            "fieldValidateRules": [
                "required"
            ]
        }
    ],
    "changelogDate": "20170307151049",
    "entityTableName": "country",
    "dto": "no",
    "pagination": "pager",
    "service": "serviceImpl"
}

Zone.json

{
    "fluentMethods": true,
    "relationships": [
        {
            "relationshipType": "one-to-many",
            "relationshipName": "country",
            "otherEntityName": "country",
            "otherEntityRelationshipName": "zone"
        }
    ],
    "fields": [
        {
            "fieldName": "name",
            "fieldType": "String",
            "fieldValidateRules": [
                "required"
            ]
        }
    ],
    "changelogDate": "20170307151049",
    "entityTableName": "zone",
    "dto": "no",
    "pagination": "pager",
    "service": "serviceImpl"
}
  • [ X] Checking this box is mandatory (this is just to show you read everything)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
pascalgrimaudcommented, Mar 9, 2017

I understand why our Travis build didn’t detect that:

0reactions
jduboiscommented, Mar 9, 2017

Thanks @pascalgrimaud !!! This was worrying me, I’m happy to have the answer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring - No EntityManager with actual transaction available for ...
The operation was attempted from a JUnit test class. ... GOT javax.persistence. ... with actual transaction available for current thread.
Read more >
Error No EntityManager with actual transaction available for ...
I get this error when trying to invoke "persist" method to save entity model to database in my Spring MVC web application.
Read more >
WB Blog - Spring @Transactional Annotation - Wilfried Barth
No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call; nested exception is javax.persistence.
Read more >
Getting 'No EntityManager with actual transaction available for ...
javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' ...
Read more >
Hapi 3.4.0 Spring Boot Issue:No EntityManager with actual ...
Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found