id = bundleVersion.getId();
assert id > 0;
assert bundleVersion.getBundle().getId() != 0 : "bundle should have been cascade persisted too";
assert bundleVersion.getBundle().getBundleType().getId() != 0 : "bundleType should have been cascade persisted too";
BundleVersionRepo bvr1 = new BundleVersionRepo(bundleVersion, repo1);
BundleVersionRepo bvr2 = new BundleVersionRepo(bundleVersion, repo2);
em.persist(bvr1);
em.persist(bvr2);
q = em.createNamedQuery(BundleVersionRepo.QUERY_FIND_BY_REPO_ID_NO_FETCH);
q.setParameter("id", repo1.getId());
assert q.getResultList().size() == 1;
assert ((BundleVersionRepo) q.getSingleResult()).getBundleVersionRepoPK().getBundleVersion()
.equals(bundleVersion);
assert ((BundleVersionRepo) q.getSingleResult()).getBundleVersionRepoPK().getRepo().equals(repo1);
q.setParameter("id", repo2.getId());
assert q.getResultList().size() == 1;
assert ((BundleVersionRepo) q.getSingleResult()).getBundleVersionRepoPK().getBundleVersion()
.equals(bundleVersion);
assert ((BundleVersionRepo) q.getSingleResult()).getBundleVersionRepoPK().getRepo().equals(repo2);
q = em.createNamedQuery(BundleVersionRepo.QUERY_FIND_BY_BUNDLE_VERSION_ID_NO_FETCH);
q.setParameter("id", bundleVersion.getId());
List<BundleVersionRepo> resultList = q.getResultList();
assert resultList.size() == 2;
BundleVersionRepoPK pk1 = new BundleVersionRepoPK(bundleVersion, repo1);
BundleVersionRepoPK pk2 = new BundleVersionRepoPK(bundleVersion, repo2);
if (resultList.get(0).getBundleVersionRepoPK().getRepo().equals(repo1)) {
assert bvr1.equals(resultList.get(0));
assert bvr2.equals(resultList.get(1));
assert pk1.equals(resultList.get(0).getBundleVersionRepoPK());
assert pk2.equals(resultList.get(1).getBundleVersionRepoPK());
} else {
assert bvr1.equals(resultList.get(1));
assert bvr2.equals(resultList.get(0));
assert pk1.equals(resultList.get(1).getBundleVersionRepoPK());
assert pk2.equals(resultList.get(0).getBundleVersionRepoPK());
}
} catch (Throwable t) {
t.printStackTrace();