-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-13020 - When proxying an entity having a private default constructor, the log message is not very clear about the problem #2564
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
Conversation
|
I would actually also substitute |
|
@raphw Good tip. Should we use |
|
Since we do not attempt accessibility, getConstructor is fine. It requires fewer security manager privileges, too. I think Byte Buddyis already configured to making the constructor public anyways. |
gsmet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladmihalcea I added some guidance about how to simplify the log thingy.
Let me know if you have any question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit overcomplicated.
I would do that this way:
catch (NoSuchMethodException e) {
throw LOG.bytecodeEnhancementFailedBecauseOfDefaultConstructor( entityName, t )
}
catch (Throwable t) {
throw LOG.bytecodeEnhancementFailed( entityName, t );
}with the log methods being defined by, for instance:
@Message(value = "Bytecode enhancement failed because no public, protected or package-private default constructor was found for entity: %s. Private constructors don't work with runtime proxies!", id = 143)
HibernateException bytecodeEnhancementFailedBecauseOfDefaultConstructor(String entityName, @Cause Exception e);JBoss-logging is very powerful, let's unleash its power!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gsmet I'll try to apply your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gsmet If we skip the log as you suggest, then the log message will look like this:
INFO DefaultLoadEventListener:132 - HHH000327: Error performing load command : org.hibernate.HibernateException: HHH000143: Bytecode enhancement failed because no public, protected or package-private default constructor was found for entity: org.hibernate.jpa.test.callbacks.PrivateConstructorTest$Parent. Private constructors don't work with runtime proxies!
I think it's better to have a separate error log entry as before as it makes it more clear what happened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
- as for the first error, I see how the way it is done would lead to this situation: we need to resolve the constructor in
postInstantiate(). This way you will have the error once and for all when getting the constructor and you can use the pattern I mentioned. - you can then revert the change you made to the error handling in
getProxy()and keep it as it was.
As much as possible, we need to avoid the reflection calls at runtime.
Sorry for not seeing it right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I'm working on it.
7572cf8 to
4ad8703
Compare
|
@raphw Thanks, Rafael. I applied your suggestions and will push it. |
4ad8703 to
6b8ccd7
Compare
…tor, the log message is not very clear about the problem
6b8ccd7 to
df3edbd
Compare
https://hibernate.atlassian.net/browse/HHH-13020