6
6
7
7
import org .hibernate .mapping .BasicValue ;
8
8
import org .hibernate .mapping .Component ;
9
+ import org .hibernate .mapping .KeyValue ;
9
10
import org .hibernate .mapping .List ;
10
11
import org .hibernate .mapping .ManyToOne ;
11
12
import org .hibernate .mapping .PersistentClass ;
@@ -29,6 +30,8 @@ void testXml(DomainModelScope domainModelScope) {
29
30
final PersistentClass rootBinding = domainModelScope .getDomainModel ().getEntityBinding ( Root .class .getName () );
30
31
validateTags ( rootBinding .getProperty ( "tags" ) );
31
32
validateCategories ( rootBinding .getProperty ( "categories" ) );
33
+ validateAdmins ( rootBinding .getProperty ( "admins" ) );
34
+ validateAdmins2 ( rootBinding .getProperty ( "admins2" ) );
32
35
}
33
36
34
37
private void validateTags (Property tags ) {
@@ -58,9 +61,6 @@ private void validateCategories(Property categories) {
58
61
else if ( "owner" .equals ( subProperty .getName () ) ) {
59
62
validateCategoryOwner ( subProperty );
60
63
}
61
- else if ( "admins" .equals ( subProperty .getName () ) ) {
62
- validateAdmins ( subProperty );
63
- }
64
64
else {
65
65
fail ( "Unexpected Category property :" + subProperty .getName () );
66
66
}
@@ -80,16 +80,41 @@ private void validateCategoryOwner(Property owenerProperty) {
80
80
81
81
}
82
82
83
- private void validateAdmins (Property adminsProperty ) {
84
- assertThat ( adminsProperty . getColumns () ). hasSize ( 1 );
85
- assertThat ( adminsProperty .getColumns (). get ( 0 ). getName () ). isEqualTo ( "root_fk" );
83
+ private void validateAdmins (Property property ) {
84
+ // mapped as many-to-many
85
+ assertThat ( property .getColumns () ). isEmpty ( );
86
86
87
- final List listValue = (List ) adminsProperty .getValue ();
87
+ final List listValue = (List ) property .getValue ();
88
88
assertThat ( listValue .getCollectionTable ().getName () ).isEqualTo ( "root_admins" );
89
89
90
+ final KeyValue foreignKey = listValue .getKey ();
91
+ assertThat ( foreignKey .getColumns () ).hasSize ( 1 );
92
+ assertThat ( foreignKey .getColumns ().get ( 0 ).getName () ).isEqualTo ( "root_fk" );
93
+
94
+ final BasicValue indexValue = (BasicValue ) listValue .getIndex ();
95
+ assertThat ( indexValue .getColumns () ).hasSize ( 1 );
96
+
97
+ final ManyToOne element = (ManyToOne ) listValue .getElement ();
98
+ assertThat ( element .getReferencedEntityName () ).isEqualTo ( User .class .getName () );
99
+ }
100
+
101
+ private void validateAdmins2 (Property property ) {
102
+ // mapped as one-to-many
103
+ assertThat ( property .getColumns () ).isEmpty ();
104
+
105
+ final List listValue = (List ) property .getValue ();
106
+ assertThat ( listValue .getColumns () ).isEmpty ();
107
+ assertThat ( listValue .getCollectionTable ().getName () ).isEqualTo ( "root_admins2" );
108
+
109
+ // key
110
+ final KeyValue foreignKey = listValue .getKey ();
111
+ assertThat ( foreignKey .getColumns () ).hasSize ( 1 );
112
+ assertThat ( foreignKey .getColumns ().get ( 0 ).getName () ).isEqualTo ( "root_fk" );
113
+
90
114
final BasicValue indexValue = (BasicValue ) listValue .getIndex ();
91
115
assertThat ( indexValue .getColumns () ).hasSize ( 1 );
92
116
93
117
final ManyToOne element = (ManyToOne ) listValue .getElement ();
118
+ assertThat ( element .getReferencedEntityName () ).isEqualTo ( User .class .getName () );
94
119
}
95
120
}
0 commit comments