Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid exceptions being thrown and caught immediately in JpaPersistentPropertyImpl.isEntity() [DATAJPA-891] #1248

Closed
spring-projects-issues opened this issue Apr 13, 2016 · 2 comments
Assignees
Labels
in: core type: enhancement

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Apr 13, 2016

Wenjie Zhang opened DATAJPA-891 and commented

In my project, I am using Spring Boot (spring-boot-starter-data-jpa) to access database. When I am trying to debug my application through Eclipse, I am getting a new IllegalArgumentException( "Not an managed type: " + cls ) from org.hibernate.jpa.internal.metamodel.MetamodelImpl.managedType, and this exception only happens when I debug the application from Eclipse, so I tried to dig into it.

Here is what I found: Spring Boot scans the package looking for JPA entities, once it finds a class under the package has @Entity defined, it will go through all of its properties and trying to find if the property is a JPA entity type or not.

The code is

// org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl.isEntity
@Override
public boolean isEntity() {
	try {
		metamodel.managedType(getActualType());
		return true;
	} catch (IllegalArgumentException o_O) {
		return false;
	}
}

However, since most of those properties in the entity class are not a JPA entity type, so I get a lot of exception here, and because Eclipse by default will suspend the process once there is any exception happens in the code, this causes a lot of noises while debugging the application. It might be a good idea try to use different mechanism to check the property type here


Backported to: 1.10.2 (Hopper SR2), 1.9.5 (Gosling SR5), 1.8.3 (Fowler SR3)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 14, 2016

Oliver Drotbohm commented

Just to make sure I get you right: yo think that we should avoid the exception to be thrown multiple times right?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 14, 2016

Wenjie Zhang commented

Hi @Oliver, thanks for reply, basically, I think we can enhance the code to avoid throwing exception (not even once)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants