[JIRA] (HHH-16907) Improve performance of flushing
by Norbert Wirges (JIRA)
Norbert Wirges ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMGY4YjBlYzIw... ) / Improvement ( https://hibernate.atlassian.net/browse/HHH-16907?atlOrigin=eyJpIjoiMGY4Yj... ) HHH-16907 ( https://hibernate.atlassian.net/browse/HHH-16907?atlOrigin=eyJpIjoiMGY4Yj... ) Improve performance of flushing ( https://hibernate.atlassian.net/browse/HHH-16907?atlOrigin=eyJpIjoiMGY4Yj... )
Issue Type: Improvement Affects Versions: 5.6 Assignee: Unassigned Components: hibernate-core Created: 06/Jul/2023 08:11 AM Priority: Major Reporter: Norbert Wirges ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... )
We found flushes to still be slow even when using a CustomEntityDirtinessStrategy and even if no changes need to be flushed.
In these cases it seems Hibernate still reads every field of every ( ? ) entity in the session to verify possible 1:1 orphan removals in Cascade.cascade() here Cascade.java#L183 ( https://github.com/hibernate/hibernate-orm/blob/2fd6f548e4f935520f85ac85b... ). In most cases the value will simply be discarded, because the type check isLogicalOneToOne() will be false anyway.
It looks as if this cost could easily be avoided by moving
>
>
>
> if ( isLogicalOneToOne( type ) )
>
>
from inside cascadeLogicalOneToOneOrphanRemoval() to before / around the call to
cascadeLogicalOneToOneOrphanRemoval()
for both callers, which would avoid the eager reading of all fields for every flush.
Example stack of the unnecessary field reading:
PojoEntityTuplizer(AbstractEntityTuplizer).getPropertyValue(Object, int) line: 610
SingleTableEntityPersister(AbstractEntityPersister).getPropertyValue(Object, int) line: 5294
Cascade.cascade(CascadingAction, CascadePoint, EventSource, EntityPersister, Object, Object) line: 184
DefaultPersistOnFlushEventListener(AbstractSaveEventListener).cascadeBeforeSave(EventSource, EntityPersister, Object, Object) line: 426
DefaultPersistOnFlushEventListener(DefaultPersistEventListener).justCascade(Map, EventSource, Object, EntityPersister) line: 167
DefaultPersistOnFlushEventListener(DefaultPersistEventListener).entityIsPersistent(PersistEvent, Map) line: 160
DefaultPersistOnFlushEventListener(DefaultPersistEventListener).onPersist(PersistEvent, Map) line: 124
1800883780.applyEventToListener(Object, Object, Object) line: not available
EventListenerGroupImpl<T>.fireEventOnEachListener(U, X, EventActionWithParameter<T,U,X>) line: 118
SessionImpl.persistOnFlush(String, Object, Map) line: 801
CascadingActions$8.cascade(EventSource, Object, String, Object, boolean) line: 341
Cascade.cascadeToOne(CascadingAction, EventSource, Object, Object, Type, CascadeStyle, Object, boolean) line: 510
Cascade.cascadeAssociation(CascadingAction, CascadePoint, EventSource, List<String>, Object, Object, Type, CascadeStyle, Object, boolean) line: 434
Cascade.cascadeProperty(CascadingAction, CascadePoint, EventSource, List<String>, Object, Object, Type, CascadeStyle, String, Object, boolean) line: 220
Cascade.cascade(CascadingAction, CascadePoint, EventSource, EntityPersister, Object, Object) line: 153
DefaultAutoFlushEventListener(AbstractFlushingEventListener).cascadeOnFlush(EventSource, EntityPersister, Object, Object) line: 159
DefaultAutoFlushEventListener(AbstractFlushingEventListener).prepareEntityFlushes(EventSource, PersistenceContext) line: 149
DefaultAutoFlushEventListener(AbstractFlushingEventListener).flushEverythingToExecutions(FlushEvent) line: 82
DefaultAutoFlushEventListener.onAutoFlush(AutoFlushEvent) line: 50
2018732354.accept(Object, Object) line: not available
EventListenerGroupImpl<T>.fireEventOnEachListener(U, BiConsumer<T,U>) line: 107
SessionImpl.autoFlushIfRequired(Set) line: 1372
SessionImpl.list(String, QueryParameters) line: 1452
QueryImpl<R>(AbstractProducedQuery<R>).doList() line: 1649
...
( https://hibernate.atlassian.net/browse/HHH-16907#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16907#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100230- sha1:e339e49 )
2 years, 9 months
[JIRA] (HHH-16906) Duplicate column exception when mapping multiple attributes to the same column in an Embeddable class, irrespective of the insertable and updatable attribute values.
by Renzo Schembri (JIRA)
Renzo Schembri ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMzhhZTEwNDE4... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16906?atlOrigin=eyJpIjoiMzhhZT... ) HHH-16906 ( https://hibernate.atlassian.net/browse/HHH-16906?atlOrigin=eyJpIjoiMzhhZT... ) Duplicate column exception when mapping multiple attributes to the same column in an Embeddable class, irrespective of the insertable and updatable attribute values. ( https://hibernate.atlassian.net/browse/HHH-16906?atlOrigin=eyJpIjoiMzhhZT... )
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Renzo Schembri ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) Components: hibernate-core Created: 06/Jul/2023 07:25 AM Priority: Major Reporter: Renzo Schembri ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... )
When mapping multiple attributes in an Embeddable class to the same column, the Column insertable and updatable attributes are not considered, and a MappingException is raised stating that “Column X is duplicated in mapping for entity Y (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)”.
I am using Hibernate 6.1.7.Final.
A test case was created within the attached pull request which is successful following the solution provided in the same pull request.
*Example:*
@Entity
@Table(name = "PARTICIPANT")
public class Participant implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private ParticipantId id;
public ParticipantId getId() {
return id;
}
public void setId(ParticipantId id) {
this.id = id;
}
}
@Embeddable
public class ParticipantId implements Serializable {
private static final long serialVersionUID = 1L;
@Embedded
@AttributeOverrides({
@AttributeOverride( name = "registrationIndex", column = @Column(name = "REGISTRATION_INDEX")),
@AttributeOverride( name = "registrationDisplay", column = @Column(name = "REGISTRATION_INDEX", insertable=false, updatable=false)),
})
private ParticipantRegistration registrationNumber;
public ParticipantRegistration getRegistrationNumber() {
return registrationNumber;
}
public void setRegistrationNumber(ParticipantRegistration registrationNumber) {
this.registrationNumber = registrationNumber;
}
}
@Embeddable
public class ParticipantRegistration implements Serializable {
private static final long serialVersionUID = 1L;
private String registrationIndex;
private String registrationDisplay;
public String getRegistrationIndex() {
return registrationIndex;
}
public void setRegistrationIndex(String registrationIndex) {
this.registrationIndex = registrationIndex;
}
public String getRegistrationDisplay() {
return registrationDisplay;
}
public void setRegistrationDisplay(String registrationDisplay) {
this.registrationDisplay = registrationDisplay;
}
}
>
>
>
> Unexpected exception thrown: org.hibernate.MappingException: Column
> 'REGISTRATION_INDEX' is duplicated in mapping for entity
> 'org.hibernate.orm.test.mapping.Participant' (use
> '@Column(insertable=false, updatable=false)' when mapping multiple
> properties to the same column)
>
>
( https://hibernate.atlassian.net/browse/HHH-16906#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16906#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100230- sha1:e339e49 )
2 years, 9 months