Search in sources :

Example 91 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class DDLTest method testLengthConstraint.

@Test
@TestForIssue(jiraKey = "HHH-5281")
public void testLengthConstraint() throws Exception {
    PersistentClass classMapping = metadata().getEntityBinding(Tv.class.getName());
    Column modelColumn = (Column) classMapping.getProperty("model").getColumnIterator().next();
    assertEquals(modelColumn.getLength(), 5);
}
Also used : Column(org.hibernate.mapping.Column) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 92 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class CascadeCircleSequenceIdTest method testCascade.

@Test
@TestForIssue(jiraKey = "HHH-5472")
public void testCascade() {
    A a = new A();
    B b = new B();
    C c = new C();
    D d = new D();
    E e = new E();
    F f = new F();
    G g = new G();
    H h = new H();
    a.getBCollection().add(b);
    b.setA(a);
    a.getCCollection().add(c);
    c.setA(a);
    b.getCCollection().add(c);
    c.setB(b);
    a.getDCollection().add(d);
    d.getACollection().add(a);
    d.getECollection().add(e);
    e.setF(f);
    f.getBCollection().add(b);
    b.setF(f);
    c.setG(g);
    g.getCCollection().add(c);
    f.setH(h);
    h.setG(g);
    Session s;
    s = openSession();
    s.getTransaction().begin();
    try {
        // Fails: says that C.b is null (even though it isn't). Doesn't fail if you persist c, g or h instead of a
        s.persist(a);
        s.flush();
    } finally {
        s.getTransaction().rollback();
        s.close();
    }
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 93 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class ElementCollectionSortingTest method testSortingEmbeddableCollectionOfPrimitives.

@Test
@TestForIssue(jiraKey = "HHH-6875")
public void testSortingEmbeddableCollectionOfPrimitives() {
    final Session session = openSession();
    session.beginTransaction();
    final Person steve = new Person();
    steve.setName("Steve");
    steve.getNickNamesAscendingNaturalSort().add("sebersole");
    steve.getNickNamesAscendingNaturalSort().add("ebersole");
    steve.getNickNamesDescendingNaturalSort().add("ebersole");
    steve.getNickNamesDescendingNaturalSort().add("sebersole");
    final Person lukasz = new Person();
    lukasz.setName("Lukasz");
    lukasz.getNickNamesAscendingNaturalSort().add("antoniak");
    lukasz.getNickNamesAscendingNaturalSort().add("lantoniak");
    lukasz.getNickNamesDescendingNaturalSort().add("lantoniak");
    lukasz.getNickNamesDescendingNaturalSort().add("antoniak");
    session.save(steve);
    session.save(lukasz);
    session.flush();
    session.clear();
    final List<String> lukaszNamesAsc = Arrays.asList("antoniak", "lantoniak");
    final List<String> lukaszNamesDesc = Arrays.asList("lantoniak", "antoniak");
    final List<String> steveNamesAsc = Arrays.asList("ebersole", "sebersole");
    final List<String> steveNamesDesc = Arrays.asList("sebersole", "ebersole");
    // Testing object graph navigation. Lazy loading collections.
    checkPersonNickNames(lukaszNamesAsc, lukaszNamesDesc, (Person) session.get(Person.class, lukasz.getId()));
    checkPersonNickNames(steveNamesAsc, steveNamesDesc, (Person) session.get(Person.class, steve.getId()));
    session.clear();
    // Testing HQL query. Eagerly fetching nicknames.
    final List<Person> result = session.createQuery("select distinct p from Person p join fetch p.nickNamesAscendingNaturalSort join fetch p.nickNamesDescendingNaturalSort order by p.name").list();
    Assert.assertEquals(2, result.size());
    checkPersonNickNames(lukaszNamesAsc, lukaszNamesDesc, result.get(0));
    checkPersonNickNames(steveNamesAsc, steveNamesDesc, result.get(1));
    // Metadata verification.
    checkSQLOrderBy(session, Person.class.getName(), "nickNamesAscendingNaturalSort", "asc");
    checkSQLOrderBy(session, Person.class.getName(), "nickNamesDescendingNaturalSort", "desc");
    session.getTransaction().rollback();
    session.close();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 94 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class RecreateCollectionTest method testUpdateCollectionOfElements.

@Test
@TestForIssue(jiraKey = "HHH-9474")
public void testUpdateCollectionOfElements() throws Exception {
    Session s = openSession();
    s.getTransaction().begin();
    Poi poi1 = new Poi("Poi 1");
    Poi poi2 = new Poi("Poi 2");
    s.save(poi1);
    s.save(poi2);
    RaceExecution race = new RaceExecution();
    s.save(race);
    Date currentTime = new Date();
    race.arriveToPoi(poi1, currentTime);
    race.expectedArrive(poi2, new Date(currentTime.getTime() + 60 * 1000));
    s.flush();
    assertEquals(2, race.getPoiArrival().size());
    StatementsCounterListener statementsCounterListener = new StatementsCounterListener();
    s.addEventListeners(statementsCounterListener);
    race.arriveToPoi(poi2, new Date(currentTime.getTime() + 2 * 60 * 1000));
    s.flush();
    assertEquals(2, race.getPoiArrival().size());
    // There is should be one UPDATE statement. Without fix there is one DELETE and two INSERT-s.
    assertEquals(1, statementsCounterListener.statements);
    s.getTransaction().rollback();
    s.close();
}
Also used : Date(java.util.Date) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 95 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class CompositeDerivedIdentityTest method testBidirectonalKeyManyToOneId.

@Test
@TestForIssue(jiraKey = "HHH-10476")
public void testBidirectonalKeyManyToOneId() {
    Product product = new Product();
    product.setName("Product 1");
    Session session = openSession();
    session.beginTransaction();
    session.save(product);
    session.getTransaction().commit();
    session.close();
    Order order = new Order();
    order.setName("Order 1");
    order.addLineItem(product, 2);
    session = openSession();
    session.beginTransaction();
    session.save(order);
    session.getTransaction().commit();
    session.close();
    session = openSession();
    session.beginTransaction();
    OrderLine orderLine = order.getLineItems().iterator().next();
    orderLine.setAmount(5);
    OrderLine orderLineGotten = session.get(OrderLine.class, orderLine);
    assertSame(orderLineGotten, orderLine);
    assertEquals(Integer.valueOf(2), orderLineGotten.getAmount());
    SessionImplementor si = (SessionImplementor) session;
    assertTrue(si.getPersistenceContext().isEntryFor(orderLineGotten));
    assertFalse(si.getPersistenceContext().isEntryFor(orderLineGotten.getOrder()));
    assertFalse(si.getPersistenceContext().isEntryFor(orderLineGotten.getProduct()));
    session.getTransaction().commit();
    session.close();
}
Also used : SessionImplementor(org.hibernate.engine.spi.SessionImplementor) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

TestForIssue (org.hibernate.testing.TestForIssue)649 Test (org.junit.Test)647 Session (org.hibernate.Session)357 EntityManager (javax.persistence.EntityManager)97 List (java.util.List)91 Transaction (org.hibernate.Transaction)88 MetadataSources (org.hibernate.boot.MetadataSources)47 ArrayList (java.util.ArrayList)38 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)38 Query (org.hibernate.Query)28 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)25 Metadata (org.hibernate.boot.Metadata)24 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)24 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)23 Map (java.util.Map)22 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)19 HashMap (java.util.HashMap)18 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)18 PersistentClass (org.hibernate.mapping.PersistentClass)18 HibernateException (org.hibernate.HibernateException)16