Skip to content
Snippets Groups Projects
Commit f966ece4 authored by Goik Martin's avatar Goik Martin
Browse files

Testing constraint violation

parent d2d67592
No related branches found
No related tags found
No related merge requests found
package rdbms2catalog;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.junit.Test;
import de.hdm_stuttgart.mi.sda1.sql2catalog.model.Description;
import de.hdm_stuttgart.mi.sda1.sql2catalog.model.Product;
public class TestSchemaConflict {
static final EntityManager em;
static {
final EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("create-drop");
em = emFactory.createEntityManager();
}
@Test(expected=javax.persistence.PersistenceException.class)
public void insertData() {
{
final EntityTransaction transaction = em.getTransaction();
transaction.begin();
final Product monkeyPickedTea = new Product(1, "Monkey Picked Tea", null);
new Description(monkeyPickedTea, 0, "Picked only by specially trained monkeys");
new Description(monkeyPickedTea, 0, "Rare wild Chinese tea"); // oops! Unique key violation
em.persist(monkeyPickedTea);
transaction.commit();
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment