Closed TomasKulhanek closed 6 years ago
Try this: After you have called dataSetService.save(dataSet) call Long DatSetID = dataSet.getId();
Andrea
On 21 Feb 2018, at 15:57, Tomas Kulhanek notifications@github.com wrote:
Assigned #27 https://github.com/h2020-westlife-eu/wp6-repository/issues/27 to @andreagia https://github.com/andreagia.
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/h2020-westlife-eu/wp6-repository/issues/27#event-1484842658, or mute the thread https://github.com/notifications/unsubscribe-auth/AMaWia43-5uMjj-IpkDJeinvCH0U8T-Iks5tXC6-gaJpZM4SNxdt.
subsequent call of getId() solves this issue. However, is it thread safe? If another dataset will be created in the mean time - getId() may return incorrect Id of last saved by somebody else.
The service that save in the database are marked with @Transactional, in principle they have to manage that the thread are safe
On 27 Feb 2018, at 12:12, Tomas Kulhanek notifications@github.com wrote:
subsequent call of getId() solves this issue. However, is it thread safe? If another dataset will be created in the mean time - getId() may return incorrect Id of last saved by somebody else.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/h2020-westlife-eu/wp6-repository/issues/27#issuecomment-368839072, or mute the thread https://github.com/notifications/unsubscribe-auth/AMaWie-ydbCeNa-tQzBi4-NuvjBvmWrqks5tY-MxgaJpZM4SNxdt.
OK. Closing this issue.
Good call! It’s great to be working with someone who can spot that.
From: Tomas Kulhanek [mailto:notifications@github.com] Sent: 27 February 2018 11:13 To: h2020-westlife-eu/wp6-repository wp6-repository@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [h2020-westlife-eu/wp6-repository] return reference of newly created object instead of void (#27)
subsequent call of getId() solves this issue. However, is it thread safe? If another dataset will be created in the mean time - getId() may return incorrect Id of last saved by somebody else.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/h2020-westlife-eu/wp6-repository/issues/27#issuecomment-368839072, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH_V1w-psklFd36NODsWNrWsY1zyVoKBks5tY-MxgaJpZM4SNxdt.
Reopening. @Transactional does not guarantee threadsafe in the context of the web service. dataSetService.save(dataSet) should return either updated dataSet or at least datasetId.
I have found that spring HibernateTemplate is thread-safe https://books.google.it/books?id=DoInCgAAQBAJ&pg=PA307&lpg=PA307&dq=hibernatetemplate+thread+safe&source=bl&ots=aHwDt93LAN&sig=QAy2_QCWzjIScWuQXFfylOIfxlk&hl=it&sa=X&ved=0ahUKEwjbnqXlo8bZAhWIr6QKHUu0CjEQ6AEIZjAF#v=onepage&q=hibernatetemplate%20thread%20safe&f=false <https://books.google.it/books?id=DoInCgAAQBAJ&pg=PA307&lpg=PA307&dq=hibernatetemplate+thread+safe&source=bl&ots=aHwDt93LAN&sig=QAy2_QCWzjIScWuQXFfylOIfxlk&hl=it&sa=X&ved=0ahUKEwjbnqXlo8bZAhWIr6QKHUu0CjEQ6AEIZjAF#v=onepage&q=hibernatetemplate thread safe&f=false> I can try to substitute the abstractdao used for the hibernate sessionFactory injection with hibernateTemplate
As test I have created a service called DatasetDaoImplH that use hibernateTempalte can you try if it work?
Andrea
On 27 Feb 2018, at 14:50, Tomas Kulhanek notifications@github.com wrote:
Reopening. @transactional https://github.com/transactional does not guarantee threadsafe in the context of the web service. dataSetService.save(dataSet) should return either updated dataSet or at least datasetId.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/h2020-westlife-eu/wp6-repository/issues/27#issuecomment-368882718, or mute the thread https://github.com/notifications/unsubscribe-auth/AMaWiWSJJV-_K6e3jdaqqt7XddjNPhS1ks5tZAgkgaJpZM4SNxdt.
We probably don't understand each other. I don't see the implication HibernateTemplate is thread safe => web service is thread safe. I think it's not true, however, it's overkill for me to create some test which will prove it. I need to focus on frontend. Can you return dataset id in a save() and make the method synchronized, please?
Ok I will try to create a test to check if REST controller is thread safe
On 27 Feb 2018, at 17:18, Tomas Kulhanek notifications@github.com wrote:
We probably don't understand each other. I don't see the implication HibernateTemplate is thread safe => web service is thread safe. I think it's not true, however, it's overkill for me to create some test which will prove it. I need to focus on frontend. Can you return dataset id in a save() and make the method synchronized, please?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/h2020-westlife-eu/wp6-repository/issues/27#issuecomment-368934287, or mute the thread https://github.com/notifications/unsubscribe-auth/AMaWiWca14saVYLdfVjgFIhNwVieILw-ks5tZCq7gaJpZM4SNxdt.
I synchronized the two critical calls. synchronized (lock1) { dataSetService.save(ds); dto.id = ds.getId(); } Unfortunately this doesn't prevent other classes to ammend dataSetService.
Current call of dataSetService.save(ds) returns void. I need to know the ID under which it was stored in DB. Return ID or by default newly created object instead of void in org.cirmmp.spring.service;
public interface DataSetService { DataSet save(DataSet dataSet); }