2424package org .hibernate .metamodel .internal .source .annotations .global ;
2525
2626import java .util .Iterator ;
27+ import java .util .List ;
28+
29+ import javax .persistence .ElementCollection ;
30+ import javax .persistence .Entity ;
31+ import javax .persistence .GeneratedValue ;
32+ import javax .persistence .Id ;
2733
2834import org .hibernate .MappingException ;
2935import org .hibernate .annotations .FetchMode ;
3339import org .hibernate .boot .registry .internal .StandardServiceRegistryImpl ;
3440import org .hibernate .metamodel .Metadata ;
3541import org .hibernate .metamodel .MetadataSources ;
36-
3742import org .hibernate .testing .junit4 .BaseUnitTestCase ;
3843import org .junit .After ;
3944import org .junit .Before ;
@@ -62,9 +67,16 @@ public void tearDown() {
6267@ Test
6368public void testSingleFetchProfile () {
6469@ FetchProfile (name = "foo" , fetchOverrides = {
65- @ FetchProfile .FetchOverride (entity = Foo .class , association = "bar " , mode = FetchMode .JOIN )
70+ @ FetchProfile .FetchOverride (entity = Foo .class , association = "bars " , mode = FetchMode .JOIN )
6671})
72+ @ Entity
6773class Foo {
74+ @ Id
75+ @ GeneratedValue
76+ public long id ;
77+
78+ @ ElementCollection
79+ public List <String > bars ;
6880}
6981
7082Metadata meta = new MetadataSources ( serviceRegistry ).addAnnotatedClass ( Foo .class ).buildMetadata ();
@@ -74,7 +86,7 @@ class Foo {
7486org .hibernate .metamodel .spi .binding .FetchProfile profile = mappedFetchProfiles .next ();
7587assertEquals ( "Wrong fetch profile name" , "foo" , profile .getName () );
7688org .hibernate .metamodel .spi .binding .FetchProfile .Fetch fetch = profile .getFetches ().iterator ().next ();
77- assertEquals ( "Wrong association name" , "bar " , fetch .getAssociation () );
89+ assertEquals ( "Wrong association name" , "bars " , fetch .getAssociation () );
7890assertEquals ( "Wrong association type" , Foo .class .getName (), fetch .getEntity () );
7991}
8092
@@ -95,12 +107,12 @@ public void testFetchProfiles() {
95107private void assertProfiles (org .hibernate .metamodel .spi .binding .FetchProfile profile ) {
96108if ( profile .getName ().equals ( "foobar" ) ) {
97109org .hibernate .metamodel .spi .binding .FetchProfile .Fetch fetch = profile .getFetches ().iterator ().next ();
98- assertEquals ( "Wrong association name" , "foobar " , fetch .getAssociation () );
110+ assertEquals ( "Wrong association name" , "fubars " , fetch .getAssociation () );
99111assertEquals ( "Wrong association type" , FooBar .class .getName (), fetch .getEntity () );
100112}
101113else if ( profile .getName ().equals ( "fubar" ) ) {
102114org .hibernate .metamodel .spi .binding .FetchProfile .Fetch fetch = profile .getFetches ().iterator ().next ();
103- assertEquals ( "Wrong association name" , "fubar " , fetch .getAssociation () );
115+ assertEquals ( "Wrong association name" , "fubars " , fetch .getAssociation () );
104116assertEquals ( "Wrong association type" , FooBar .class .getName (), fetch .getEntity () );
105117}
106118else {
@@ -111,23 +123,37 @@ else if ( profile.getName().equals( "fubar" ) ) {
111123@ Test (expected = MappingException .class )
112124public void testNonJoinFetchThrowsException () {
113125@ FetchProfile (name = "foo" , fetchOverrides = {
114- @ FetchProfile .FetchOverride (entity = Foo .class , association = "bar " , mode = FetchMode .SELECT )
126+ @ FetchProfile .FetchOverride (entity = Foo .class , association = "bars " , mode = FetchMode .SELECT )
115127})
128+ @ Entity
116129class Foo {
130+ @ Id
131+ @ GeneratedValue
132+ public long id ;
133+
134+ @ ElementCollection
135+ public List <String > bars ;
117136}
118137
119138new MetadataSources ( serviceRegistry ).addAnnotatedClass ( Foo .class ).buildMetadata ();
120139}
121140
122141@ FetchProfiles ( {
123142@ FetchProfile (name = "foobar" , fetchOverrides = {
124- @ FetchProfile .FetchOverride (entity = FooBar .class , association = "foobar " , mode = FetchMode .JOIN )
143+ @ FetchProfile .FetchOverride (entity = FooBar .class , association = "fubars " , mode = FetchMode .JOIN )
125144}),
126145@ FetchProfile (name = "fubar" , fetchOverrides = {
127- @ FetchProfile .FetchOverride (entity = FooBar .class , association = "fubar " , mode = FetchMode .JOIN )
146+ @ FetchProfile .FetchOverride (entity = FooBar .class , association = "fubars " , mode = FetchMode .JOIN )
128147})
129148})
149+ @ Entity
130150class FooBar {
151+ @ Id
152+ @ GeneratedValue
153+ public long id ;
154+
155+ @ ElementCollection
156+ public List <String > fubars ;
131157}
132158}
133159
0 commit comments