Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,58 @@ public void test(TestContext context) { | |
); | ||
} | ||
|
||
@Test | ||
public void testFailOnMultipleRemoves(TestContext context) { | ||
Book book1 = new Book("Feersum Endjinn"); | ||
Book book2 = new Book("Use of Weapons"); | ||
Book book3 = new Book( "Third Book"); | ||
Book book4 = new Book( "Fourth Book"); | ||
Book book5 = new Book( "Fifth Book"); | ||
Author author = new Author("Iain M Banks"); | ||
author.books.add(book1); | ||
author.books.add(book2); // << remove(1) | ||
author.books.add(book3); // << remove(2) | ||
author.books.add(book4); | ||
author.books.add(book5); | ||
|
||
test(context, | ||
getMutinySessionFactory() | ||
.withTransaction( (session, transaction) -> session.persistAll(author) ) | ||
.chain( () -> getMutinySessionFactory() | ||
.withTransaction( (session, transaction) -> session.find(Author.class, author.id) | ||
.invoke( a -> context.assertFalse( Hibernate.isInitialized(a.books) ) ) | ||
.chain( a -> session.fetch(a.books) ) | ||
.invoke( books -> context.assertEquals( 5, books.size() ) ) | ||
) | ||
) | ||
.chain( () -> getMutinySessionFactory() | ||
.withTransaction( (session, transaction) -> session.createQuery("select distinct a from Author a left join fetch a.books", Author.class ) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
.getSingleResult() | ||
.invoke( a -> context.assertTrue( Hibernate.isInitialized(a.books) ) ) | ||
.invoke( a -> context.assertEquals( 5, a.books.size() ) ) | ||
This comment has been minimized.
Sorry, something went wrong.
DavideD
|
||
) | ||
) | ||
.chain( () -> getMutinySessionFactory() | ||
.withTransaction( (session, transaction) -> session.find(Author.class, author.id) | ||
.chain( a -> session.fetch(a.books) ) | ||
.invoke( books -> { | ||
books.remove( 1 ); | ||
books.remove( 1 ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
blafond
Author
Owner
|
||
} ) | ||
) | ||
) | ||
.chain( () -> getMutinySessionFactory() | ||
.withTransaction( (session, transaction) -> session.find(Author.class, author.id) | ||
.chain( a -> session.fetch(a.books) ) | ||
.invoke( books -> { | ||
context.assertEquals( 3, books.size() ); | ||
context.assertEquals( book3.title, books.get(1).title ); | ||
} ) | ||
) | ||
) | ||
); | ||
} | ||
|
||
@Embeddable | ||
static class Book { | ||
Book(String title) { | ||
|
Why
distinct
?