Skip to content

Commit ee0cf67

Browse files
committed
HHH-6005 - DefaultComponentSafeNamingStrategy breaks @ElementCollection of @embeddables - testcase
1 parent 953260e commit ee0cf67

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.test.namingstrategy.components;
25+
26+
import org.hibernate.cfg.Configuration;
27+
import org.hibernate.cfg.DefaultComponentSafeNamingStrategy;
28+
import org.hibernate.mapping.Bag;
29+
import org.hibernate.mapping.Column;
30+
import org.hibernate.mapping.PersistentClass;
31+
import org.hibernate.mapping.Property;
32+
import org.hibernate.mapping.SimpleValue;
33+
34+
import org.hibernate.testing.FailureExpected;
35+
import org.hibernate.testing.junit4.BaseUnitTestCase;
36+
import org.junit.Test;
37+
38+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
39+
import static org.junit.Assert.assertEquals;
40+
import static org.junit.Assert.assertFalse;
41+
42+
/**
43+
* @author Steve Ebersole
44+
*/
45+
public class ComponentNamingStrategyTest extends BaseUnitTestCase {
46+
@Test
47+
public void testDefaultNamingStrategy() {
48+
Configuration cfg = new Configuration();
49+
cfg.addAnnotatedClass( Container.class ).addAnnotatedClass( Item.class );
50+
cfg.buildMappings();
51+
PersistentClass pc = cfg.getClassMapping( Container.class.getName() );
52+
Property p = pc.getProperty( "items" );
53+
Bag value = assertTyping( Bag.class, p.getValue() );
54+
SimpleValue elementValue = assertTyping( SimpleValue.class, value.getElement() );
55+
assertEquals( 1, elementValue.getColumnSpan() );
56+
Column column = assertTyping( Column.class, elementValue.getColumnIterator().next() );
57+
assertFalse( column.getName().contains( "&&" ) );
58+
}
59+
60+
@Test
61+
@FailureExpected( jiraKey = "HHH-6005" )
62+
public void testComponentSafeNamingStrategy() {
63+
Configuration cfg = new Configuration();
64+
cfg.setNamingStrategy( DefaultComponentSafeNamingStrategy.INSTANCE );
65+
cfg.addAnnotatedClass( Container.class ).addAnnotatedClass( Item.class );
66+
cfg.buildMappings();
67+
PersistentClass pc = cfg.getClassMapping( Container.class.getName() );
68+
Property p = pc.getProperty( "items" );
69+
Bag value = assertTyping( Bag.class, p.getValue() );
70+
SimpleValue elementValue = assertTyping( SimpleValue.class, value.getElement() );
71+
assertEquals( 1, elementValue.getColumnSpan() );
72+
Column column = assertTyping( Column.class, elementValue.getColumnIterator().next() );
73+
assertFalse( column.getName().contains( "&&" ) );
74+
}
75+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.test.namingstrategy.components;
25+
26+
import java.util.List;
27+
import javax.persistence.ElementCollection;
28+
import javax.persistence.Entity;
29+
import javax.persistence.Id;
30+
31+
/**
32+
* @author Steve Ebersole
33+
*/
34+
@Entity
35+
public class Container {
36+
@Id
37+
private Integer id;
38+
@ElementCollection
39+
private List<Item> items;
40+
41+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.test.namingstrategy.components;
25+
26+
import javax.persistence.Embeddable;
27+
28+
/**
29+
* @author Steve Ebersole
30+
*/
31+
@Embeddable
32+
public class Item {
33+
private String name;
34+
}

0 commit comments

Comments
 (0)