HHH-6697 Added test case.
This commit is contained in:
parent
d76358cd03
commit
3bd95da6c5
|
@ -32,9 +32,11 @@ import java.io.ObjectOutputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.persistence.EntityExistsException;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityNotFoundException;
|
import javax.persistence.EntityNotFoundException;
|
||||||
import javax.persistence.FlushModeType;
|
import javax.persistence.FlushModeType;
|
||||||
|
import javax.persistence.PersistenceException;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
|
@ -234,6 +236,39 @@ public class EntityManagerTest extends TestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPersistExisting() throws Exception {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
Wallet w = new Wallet();
|
||||||
|
w.setBrand( "Lacoste" );
|
||||||
|
w.setModel( "Minimic" );
|
||||||
|
w.setSerial( "0100202002" );
|
||||||
|
em.persist( w );
|
||||||
|
w = new Wallet();
|
||||||
|
w.setBrand( "Lacoste" );
|
||||||
|
w.setModel( "Minimic" );
|
||||||
|
w.setSerial( "0100202002" );
|
||||||
|
try {
|
||||||
|
em.persist( w );
|
||||||
|
}
|
||||||
|
catch ( EntityExistsException eee ) {
|
||||||
|
//success
|
||||||
|
if ( em.getTransaction() != null ) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
}
|
||||||
|
em.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
em.getTransaction().commit();
|
||||||
|
fail( "Should have raised an exception" );
|
||||||
|
}
|
||||||
|
catch (PersistenceException pe) {}
|
||||||
|
finally {
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testSerializableException() throws Exception {
|
public void testSerializableException() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
Loading…
Reference in New Issue