I have a question regarding EntityLoadingEvents (https://docs.jmix.io/jmix/data-access/entity-events.html#saving-loading-events).
I implemented such an event listener which resolves additional attribute data on loading an entity.
package com.company.app.demo.entity.customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import io.jmix.core.event.EntityLoadingEvent;
@Component
public class CustomerEventListener
{
@Autowired
private ICustomerService customerService;
@EventListener
public void onCustomerLoading(final EntityLoadingEvent<Customer> anEvent)
{
customerService.loadTransientFieldsCurrent(anEvent.getEntity());
}
}
That work’s as expected when using a standard lookup.
<collection id="customersDc" class="com.company.app.demo.entity.customer.Customer">
<fetchPlan extends="_base"/>
<loader id="customersDl">
<query>
<![CDATA[SELECT e FROM demo_Customer e]]>
</query>
</loader>
</collection>
It does not work, when the customer is accessed through another entity e.g. Order by accessing a method: Order#getCustomer()
.
package com.company.app.demo.entity.order;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
/* ... */
import io.jmix.core.entity.annotation.OnDeleteInverse;
import io.jmix.core.metamodel.annotation.JmixEntity;
/* ... */
@JmixEntity
@Entity(name = "demo_Order")
public class Order
{
/* ... */
@OnDeleteInverse(DeletePolicy.DENY)
@JoinColumn(name = "CONSUMER_ID")
@ManyToOne(fetch = FetchType.LAZY)
private Customer customer;
/* ... */
public Customer getCustomer()
{
return customer;
}
/* ... */
}
Is that behavior intended?