Hibernate Shared SessionsJava

Java-Forum
Anonymous
 Hibernate Shared Sessions

Post by Anonymous »

Seit ich zu Hibernate 6.x+ Migrierte, hatte ich Probleme mit gemeinsamen Sitzungen in Einheitssitzungen. Aufzeichnung (Banane), aber ich empfange die Nachricht: < /p>

Code: Select all

Caused by: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [banana#123]
< /code>
Dieses Verhalten trat in Version 5.x von Hibernate nicht auf, sondern nur in Version 6.x.@SpringBootTest
@RunWith(SpringRunner.class)
public class BananaConcurrentDeletedTest {

private static final int THREADS = 10;
private static final int ITERATIONS = 15;
private static final String BANANA_ID = "123";

@Autowired
private BananaConcurrentDeletedFixture fixture;

@Test
public void ensureConcurrentBananaIsCorrect() throws Exception {
createBanana();

Set bananaIds = new HashSet();
ids.add(BANANA_ID);

Target target = new Target(ids);

for (int i=0; i
Meine Zielimplementierung: < /p>
private class Target implements Runnable {

private final CountDownLatch startLatch = new CountDownLatch(THREADS);
private final CountDownLatch endLatch = new CountDownLatch(THREADS);

private final Set ids;

public Target(Set ids) {
this.ids = ids;
}

@Override
public void run() {
try {
startLatch.countDown();
startLatch.await();

for (int i=0; i
Fixture -Methoden: < /p>
void createBanana(String BANANA_ID){
Banana banana = new Banana(BANANA_ID);
createBananaService.save(banana);
}

void deleteBanana(String BANANA_ID){
bananaService.deleteBananaById(BANANA_ID);
}

< /code>
Das [url=viewtopic.php?t=20324]Problem[/url] tritt auf, wenn ich das Objekt vor dem Initialisieren der Threads erstelle. Ich habe bereits versucht, es mit @transactional (Propagation = fordert_new) 
zu isolieren, aber ohne Erfolg.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post