|
23 | 23 | */
|
24 | 24 | package org.hibernate.jpa.test.graphs.find;
|
25 | 25 |
|
26 |
| -import org.hibernate.Hibernate; |
27 |
| -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; |
28 |
| -import org.junit.Test; |
| 26 | +import static org.junit.Assert.assertTrue; |
29 | 27 |
|
30 |
| -import javax.persistence.*; |
31 | 28 | import java.util.HashMap;
|
32 | 29 | import java.util.Map;
|
33 | 30 |
|
34 |
| -import static org.junit.Assert.*; |
| 31 | +import javax.persistence.Entity; |
| 32 | +import javax.persistence.EntityGraph; |
| 33 | +import javax.persistence.EntityManager; |
| 34 | +import javax.persistence.FetchType; |
| 35 | +import javax.persistence.GeneratedValue; |
| 36 | +import javax.persistence.Id; |
| 37 | +import javax.persistence.ManyToOne; |
| 38 | + |
| 39 | +import org.hibernate.Hibernate; |
| 40 | +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; |
| 41 | +import org.junit.Test; |
35 | 42 |
|
36 | 43 | /**
|
37 | 44 | * @author Christian Bauer
|
38 | 45 | */
|
39 | 46 | public class FindEntityGraphTests extends BaseEntityManagerFunctionalTestCase {
|
40 | 47 |
|
41 |
| - @Override |
42 |
| - protected Class<?>[] getAnnotatedClasses() { |
43 |
| - return new Class[]{Foo.class, Bar.class, Baz.class}; |
44 |
| - } |
| 48 | + @Override |
| 49 | + protected Class<?>[] getAnnotatedClasses() { |
| 50 | + return new Class[] { Foo.class, Bar.class, Baz.class }; |
| 51 | + } |
45 | 52 |
|
46 |
| - @Test |
47 |
| - public void loadParallelManyToOne() { |
48 |
| - EntityManager em = getOrCreateEntityManager(); |
49 |
| - em.getTransaction().begin(); |
| 53 | + @Test |
| 54 | + public void loadMultipleAssociations() { |
| 55 | + EntityManager em = getOrCreateEntityManager(); |
| 56 | + em.getTransaction().begin(); |
50 | 57 |
|
51 |
| - Bar bar = new Bar(); |
52 |
| - bar.id = 1; |
53 |
| - bar.name = "bar"; |
54 |
| - em.persist(bar); |
| 58 | + Bar bar = new Bar(); |
| 59 | + bar.name = "bar"; |
| 60 | + em.persist( bar ); |
55 | 61 |
|
56 |
| - Baz baz = new Baz(); |
57 |
| - baz.id = 2; |
58 |
| - baz.name = "baz"; |
59 |
| - em.persist(baz); |
| 62 | + Baz baz = new Baz(); |
| 63 | + baz.name = "baz"; |
| 64 | + em.persist( baz ); |
60 | 65 |
|
61 |
| - Foo foo = new Foo(); |
62 |
| - foo.id = 3; |
63 |
| - foo.name = "foo"; |
64 |
| - foo.bar = bar; |
65 |
| - foo.baz = baz; |
66 |
| - em.persist(foo); |
| 66 | + Foo foo = new Foo(); |
| 67 | + foo.name = "foo"; |
| 68 | + foo.bar = bar; |
| 69 | + foo.baz = baz; |
| 70 | + em.persist( foo ); |
67 | 71 |
|
68 |
| - em.getTransaction().commit(); |
69 |
| - em.close(); |
| 72 | + em.getTransaction().commit(); |
| 73 | + em.clear(); |
70 | 74 |
|
71 |
| - em = getOrCreateEntityManager(); |
72 |
| - em.getTransaction().begin(); |
| 75 | + em.getTransaction().begin(); |
73 | 76 |
|
74 |
| - EntityGraph<Foo> fooGraph = em.createEntityGraph(Foo.class); |
75 |
| - fooGraph.addAttributeNodes("bar", "baz"); |
| 77 | + EntityGraph<Foo> fooGraph = em.createEntityGraph( Foo.class ); |
| 78 | + fooGraph.addAttributeNodes( "bar", "baz" ); |
76 | 79 |
|
77 |
| - Map<String, Object> properties = new HashMap<String, Object>(); |
78 |
| - properties.put("javax.persistence.loadgraph", fooGraph); |
| 80 | + Map<String, Object> properties = new HashMap<String, Object>(); |
| 81 | + properties.put( "javax.persistence.loadgraph", fooGraph ); |
79 | 82 |
|
80 |
| - Foo result = em.find(Foo.class, foo.id, properties); |
| 83 | + Foo result = em.find( Foo.class, foo.id, properties ); |
81 | 84 |
|
82 |
| - assertTrue(Hibernate.isInitialized(result)); |
83 |
| - assertTrue(Hibernate.isInitialized(result.bar)); |
84 |
| - assertTrue(Hibernate.isInitialized(result.baz)); |
| 85 | + assertTrue( Hibernate.isInitialized( result ) ); |
| 86 | + assertTrue( Hibernate.isInitialized( result.bar ) ); |
| 87 | + assertTrue( Hibernate.isInitialized( result.baz ) ); |
85 | 88 |
|
86 |
| - em.getTransaction().commit(); |
87 |
| - em.close(); |
88 |
| - } |
| 89 | + em.getTransaction().commit(); |
| 90 | + em.close(); |
| 91 | + } |
89 | 92 |
|
90 |
| - @Entity |
91 |
| - public static class Foo { |
| 93 | + @Entity |
| 94 | + public static class Foo { |
92 | 95 |
|
93 |
| - @Id |
94 |
| - public Integer id; |
| 96 | + @Id |
| 97 | + @GeneratedValue |
| 98 | + public Integer id; |
95 | 99 |
|
96 |
| - public String name; |
| 100 | + public String name; |
97 | 101 |
|
98 |
| - @ManyToOne(fetch = FetchType.LAZY) |
99 |
| - public Bar bar; |
| 102 | + @ManyToOne(fetch = FetchType.LAZY) |
| 103 | + public Bar bar; |
100 | 104 |
|
101 |
| - @ManyToOne(fetch = FetchType.LAZY) |
102 |
| - public Baz baz; |
103 |
| - } |
| 105 | + @ManyToOne(fetch = FetchType.LAZY) |
| 106 | + public Baz baz; |
| 107 | + } |
104 | 108 |
|
105 |
| - @Entity |
106 |
| - public static class Bar { |
| 109 | + @Entity |
| 110 | + public static class Bar { |
107 | 111 |
|
108 |
| - @Id |
109 |
| - public Integer id; |
| 112 | + @Id |
| 113 | + @GeneratedValue |
| 114 | + public Integer id; |
110 | 115 |
|
111 |
| - public String name; |
112 |
| - } |
| 116 | + public String name; |
| 117 | + } |
113 | 118 |
|
114 |
| - @Entity |
115 |
| - public static class Baz { |
| 119 | + @Entity |
| 120 | + public static class Baz { |
116 | 121 |
|
117 |
| - @Id |
118 |
| - public Integer id; |
| 122 | + @Id |
| 123 | + @GeneratedValue |
| 124 | + public Integer id; |
119 | 125 |
|
120 |
| - public String name; |
121 |
| - } |
| 126 | + public String name; |
| 127 | + } |
122 | 128 |
|
123 | 129 | }
|
0 commit comments