Skip to content

Commit 8c8e729

Browse files
gredlersebersole
authored andcommitted
Test for HHH-8615 (no fix).
1 parent 46a6293 commit 8c8e729

File tree

5 files changed

+408
-0
lines changed

5 files changed

+408
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2010, 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.annotations.type.dynamicparameterized;
25+
26+
import java.util.Date;
27+
28+
import javax.persistence.Column;
29+
import javax.persistence.Id;
30+
import javax.persistence.MappedSuperclass;
31+
import javax.persistence.Temporal;
32+
import javax.persistence.TemporalType;
33+
34+
import org.hibernate.annotations.TypeDef;
35+
36+
/**
37+
* @author Daniel Gredler
38+
*/
39+
@MappedSuperclass
40+
@TypeDef(name = "string", typeClass = MyStringType.class, defaultForType = String.class)
41+
public abstract class AbstractEntity {
42+
43+
@Id
44+
@Temporal(TemporalType.DATE)
45+
@Column(name = "ID")
46+
Date id;
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2010, 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.annotations.type.dynamicparameterized;
25+
26+
import java.util.Date;
27+
28+
import org.hibernate.Session;
29+
import org.hibernate.Transaction;
30+
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
31+
import org.junit.Assert;
32+
import org.junit.Test;
33+
34+
/**
35+
* @author Daniel Gredler
36+
*/
37+
public class DynamicParameterizedTypeTest extends BaseCoreFunctionalTestCase {
38+
39+
@Override
40+
protected Class<?>[] getAnnotatedClasses() {
41+
return new Class[] { AbstractEntity.class, Entity1.class, Entity2.class };
42+
}
43+
44+
@Test
45+
public void testParameterValues() {
46+
47+
Session s = openSession();
48+
Transaction tx = s.beginTransaction();
49+
50+
Entity1 entity1 = new Entity1();
51+
entity1.id = new Date( 0 );
52+
53+
Entity2 entity2 = new Entity2();
54+
entity2.id = new Date( 0 );
55+
56+
s.persist( entity1 );
57+
s.persist( entity2 );
58+
s.flush();
59+
s.clear();
60+
61+
entity1 = (Entity1) s.byId( Entity1.class ).load( entity1.id );
62+
entity2 = (Entity2) s.byId( Entity2.class ).load( entity2.id );
63+
64+
Assert.assertEquals( "ENTITY1.PROP1", entity1.entity1_Prop1 );
65+
Assert.assertEquals( "ENTITY1.PROP2", entity1.entity1_Prop2 );
66+
Assert.assertEquals( "ENTITY1.PROP3.FOO", entity1.entity1_Prop3 );
67+
Assert.assertEquals( "ENTITY1.PROP4.BAR", entity1.entity1_Prop4 );
68+
Assert.assertEquals( "ENTITY1.PROP5", entity1.entity1_Prop5 );
69+
Assert.assertEquals( "ENTITY1.PROP6", entity1.entity1_Prop6 );
70+
71+
Assert.assertEquals( "ENTITY2.PROP1", entity2.entity2_Prop1 );
72+
Assert.assertEquals( "ENTITY2.PROP2", entity2.entity2_Prop2 );
73+
Assert.assertEquals( "ENTITY2.PROP3", entity2.entity2_Prop3 );
74+
Assert.assertEquals( "ENTITY2.PROP4", entity2.entity2_Prop4 );
75+
Assert.assertEquals( "ENTITY2.PROP5.BLAH", entity2.entity2_Prop5 );
76+
Assert.assertEquals( "ENTITY2.PROP6.YEAH", entity2.entity2_Prop6 );
77+
78+
tx.rollback();
79+
s.close();
80+
}
81+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2010, 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.annotations.type.dynamicparameterized;
25+
26+
import javax.persistence.Access;
27+
import javax.persistence.AccessType;
28+
import javax.persistence.Column;
29+
import javax.persistence.Entity;
30+
import javax.persistence.Table;
31+
32+
import org.hibernate.annotations.Parameter;
33+
import org.hibernate.annotations.Type;
34+
35+
/**
36+
* @author Daniel Gredler
37+
*/
38+
@Entity
39+
@Table(name = "ENTITY1")
40+
@Access(AccessType.FIELD)
41+
public class Entity1 extends AbstractEntity {
42+
43+
@Column(name = "PROP1")
44+
String entity1_Prop1;
45+
46+
@Column(name = "PROP2")
47+
String entity1_Prop2;
48+
49+
@Column(name = "PROP3")
50+
@Type(type = "string", parameters = @Parameter(name = "suffix", value = "foo"))
51+
String entity1_Prop3;
52+
53+
@Column(name = "PROP4")
54+
@Type(type = "string", parameters = @Parameter(name = "suffix", value = "bar"))
55+
String entity1_Prop4;
56+
57+
@Column(name = "PROP5")
58+
@Type(type = "string")
59+
String entity1_Prop5;
60+
61+
@Column(name = "PROP6")
62+
@Type(type = "string")
63+
String entity1_Prop6;
64+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2010, 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.annotations.type.dynamicparameterized;
25+
26+
import javax.persistence.Access;
27+
import javax.persistence.AccessType;
28+
import javax.persistence.Column;
29+
import javax.persistence.Entity;
30+
import javax.persistence.Table;
31+
32+
import org.hibernate.annotations.Parameter;
33+
import org.hibernate.annotations.Type;
34+
35+
/**
36+
* @author Daniel Gredler
37+
*/
38+
@Entity
39+
@Table(name = "ENTITY2")
40+
@Access(AccessType.FIELD)
41+
public class Entity2 extends AbstractEntity {
42+
43+
@Column(name = "PROP1")
44+
@Type(type = "string")
45+
String entity2_Prop1;
46+
47+
@Column(name = "PROP2")
48+
@Type(type = "string")
49+
String entity2_Prop2;
50+
51+
@Column(name = "PROP3")
52+
String entity2_Prop3;
53+
54+
@Column(name = "PROP4")
55+
String entity2_Prop4;
56+
57+
@Column(name = "PROP5")
58+
@Type(type = "string", parameters = @Parameter(name = "suffix", value = "blah"))
59+
String entity2_Prop5;
60+
61+
@Column(name = "PROP6")
62+
@Type(type = "string", parameters = @Parameter(name = "suffix", value = "yeah"))
63+
String entity2_Prop6;
64+
}

0 commit comments

Comments
 (0)