Hi Guillaume,
Can you please check the behavior of with the Javassist enhancer in this
particular case? I believe it's the correct one, but one has to double
check.
Also, on a related issue, please check the comments I made on
https://hibernate.atlassian.net/browse/HHH-12593 about property access.
I think we need to sort out both aspects, the interception and enhancing
as mapped collection, in order to support this case properly. The former
is a bug but for the latter I don't see a good enough solution.
Let me know what you find so we can proceed on solving this out.
Regards,
Luis Barreiro
Middleware Performance Team
<
https://red.ht/sig>
On 06/11/2018 06:34 PM, Guillaume Smet wrote:
Hi Luis,
This question is related to
https://hibernate.atlassian.net/browse/HHH-12601 .
AFAICS, the following case (e.g. having the fields defined in the
parent class and the laziness defined in the child class) is not
working very well with bytecode enhancement:
====
@Entity
public class RequestWithLazyEvents extends RelatedToEvents {
@ManyToMany(fetch = FetchType.LAZY)
@Fetch(FetchMode.SELECT)
public Set<Event> getEvents() {
return events;
}
}
@MappedSuperclass
public abstract class RelatedToEvents extends Base {
protected Set<Event> events = new LinkedHashSet<>();
public void setEvents(Set<Event> events) {
this.events = events;
}
}
====
By not working very well, I mean that the interceptor read/write
methods are defined in the child class but the getters and setters are
not intercepted because we only intercept the getters/setters if the
fields are defined in the current class:
See this method in PersistentAttributeTransformer and especially the
last test:
====
private boolean isEnhanced(String owner, String name, String desc) {
for ( FieldDescription enhancedField : enhancedFields ) {
if ( enhancedField.getName().equals( name )
&& enhancedField.getDescriptor().equals( desc )
&&
enhancedField.getDeclaringType().asErasure().getInternalName().equals(
owner ) ) {
return true;
}
}
return false;
}
====
(Note that supporting this case is not only a matter of removing the test)
I don't know if it's a case we want to support or not but I'm a bit
worried that we don't throw any error and the collection is not loaded
at all (as the rest of ORM supposes the enhancer will do the work).
You end up saving the collection in the database and when you get it
back the collection is always empty.
It can lead to serious data loss if you save the entity back to the
database thus I think it's somewhat critical to fix it.
WDYT?
--
Guillaume