Hi all!
I have some issue when I perform http TestNG tests through multiple threads.
Code:
@Test
public void updateFrameWithData1() {
//create unique frame
// then update it
}
@Test
public void updateFrameWithData2() {
//create unique frame
// then update it
}
and so on.. multiple tests via for example 8 threads
If I run tests in one thread all is ok! But in the above case I got 500 error response - No row with the given identifier exists
And on the server I see such error:
Code:
javax.persistence.EntityNotFoundException: No row with the given identifier exists: [com.aginity.amp.catalogservice.domain.model.workspace.asset.frame.frame.FrameLogic#48951]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:111)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1419)
at
I have
Code:
hibernate.current_session_context_class: thread
for current session.
Hibernate version is 5.2.8
The structure of my classes:
Code:
public class Frame {
@OneToOne(cascade = {CascadeType.ALL}, orphanRemoval = true, fetch = FetchType.EAGER)
@JoinColumn(name = "frame_logic_key", referencedColumnName = "frame_logic_key")
private FrameLogic logic;
//other fields
}
@AttributeOverride(name = "id", column = @Column(name = "view_frame_logic_key"))
public class FrameLogic extends IdentifiedDomainObject {
// fields of class
}
So the relationship is unidirectional via "frame_logic_key" column in corresponding tables of Frame and FrameLogic.
The EntityNotFoundException causing code is in one of Repository method -
Code:
Collection<FrameReference> dependenciesOfFrame(AssetId frameId) {
Query referencesQuery = this.getSession().createNativeQuery(
"SELECT a.asset_id as frame_id, fr.name .... WHERE a.asset_id=:frameId"
);
referencesQuery.setParameter("frameId", frameId.id());
List<Object[]> frameIdsWithRefDetails = referencesQuery.list();
Multimap<String, FrameReference> refDetailsByFrameId = convert(frameIdsWithRefDetails)
Set<String> ids = refDetailsByFrameId.keySet();
Query framesQuery = this.getSession().createQuery(
"from com.aginity.amp.catalogservice.domain.model.workspace.asset.frame.Frame as _obj_ "
+ "where _obj_.assetId.id in (:ids)");
framesQuery.setParameterList("ids", ids);
Collection<Frame> frames = framesQuery.list(); // here is when exception occurs!
}
In either create or update frame flow it calls
Code:
dependenciesOfFrame()
to validate some business logic and after that it finally calls
Code:
this.getSession().saveOrUpdate(frame);
I am stuck where the problem can be.
Maybe
https://stackoverflow.com/questions/5512138/calling-hibernate-query-list-method-generates-errors is somehow related to my problem but I am nor sure.
Any ideas why the issue may occur?