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);
}
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();
}
}
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();
}
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();
}
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();
}
Aggregations