JUnit test - Entity is a change tracker, but has no property change listener

Hi,
I am using the workshop quickstart project and I’m trying to create a client and load it from the database.

@Test
public void testCreateClient() {
Client client = metadata.create(Client.class);
client.setName(“Telent”);
client.setEmail("j7e@email.com");
client.setPhoneNumber(“167b553467213”);
dataManager.commit(client);
Client loaded = dataManager.load(LoadContext.create(Client.class)
.setId(client.getId()).setView(View.LOCAL));
assertNotNull(loaded);
assertEquals(client.getName(), loaded.getName());
dataManager.remove(loaded);
}

This gives me error:
org.springframework.dao.InvalidDataAccessApiUsageException: Entity ‘com.company.workshop.entity.Client-ad7c4b4d-bb4f-eefe-3f90-60fcf07bb220 [managed]’ is a ChangeTracker but has no PropertyChangeListener; nested exception is java.lang.IllegalStateException: Entity ‘com.company.workshop.entity.Client-ad7c4b4d-bb4f-eefe-3f90-60fcf07bb220 [managed]’ is a ChangeTracker but has no PropertyChangeListener

How can I fix this?

Hi,

How do you run the test? If the problem occurs when running in IntelliJ, try execute:

gradlew cleanIdea assemble idea

It should correctly setup IntelliJ project files.

1 Like

I am working with Eclipse, I updated the eclipse files from CUBA and build gradle multiple times, but still it seems to have this error. I will recheck tomorrow

I did a little bit of debugging, and it seems that when the DataManagerBean is trying to commit the entity through the dataStore it has no MAIN store, so instead it is detached, without propertyChangeListeners.
debug

So when the following command is entered:

Candidate loaded = dataManager.load(LoadContext.create(Candidate.class)
.setId(candidate.getId()).setView(View.LOCAL));

I get the error:
is a ChangeTracker but has no PropertyChangeListener; nested exception is java.lang.IllegalStateException

The cause of such an error is usually that a non-enhanced version of the entity class is used.

When you assemble the project, the enhance task puts enhanced classes into separate directory: modules/global/build/enhanced-classes. At the same time, non-enhanced classes are in modules/global/build/classes.

So in an IDE, this enhanced-classes directory must be earlier in the classpath for running tests. Normally, the task creating IDE project files forms the correct classpath. Please check it.

I checked the directories, they exist, but I found this in the global directory, so I’m not sure if the path is completely correct.
debug-2

The path seems to have backslash and right before the enhanced-classes directory it has a forward slash.
So maybe this isn’t correct?
Tried to rewrite the path manually with all forward slashes, but not sure how to rebuild :\

Filed an issue: https://youtrack.cuba-platform.com/issue/PL-10414
You can work around it if you manually add /main at the end of the classpath entry:

.../modules/global/build/enhanced-classes/main

Yes, it works like this, thanks.

P.S. When I update the eclipse files from CUBA, the .classpath file changes itself to the wrong default path, but I guess that will be fixed within the issue.

Thank you for the confirmation. The fix will be released in platform 6.8.2.

I am using the latest version of Cuba Studio 6.8.2 but still getting the same error.

I am also getting the same error while trying to test my service.

The problem is fixed in platform 6.8.2. It has nothing to do with Studio, it’s a framework issue. Please check your platform version.