File tree Expand file tree Collapse file tree 4 files changed +221
-0
lines changed
hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel Expand file tree Collapse file tree 4 files changed +221
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ /*
3
+ * Hibernate, Relational Persistence for Idiomatic Java
4
+ *
5
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
6
+ * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7
+ */
8
+ package org .hibernate .jpa .test .metamodel ;
9
+
10
+ import java .io .Serializable ;
11
+ import javax .persistence .EmbeddedId ;
12
+ import javax .persistence .MappedSuperclass ;
13
+
14
+ /**
15
+ * @author Christian Beikov
16
+ */
17
+ @ MappedSuperclass
18
+ public abstract class BaseEmbeddedEntity <I extends Serializable > implements Serializable {
19
+
20
+ private I id ;
21
+
22
+ public BaseEmbeddedEntity () {
23
+ }
24
+
25
+ public BaseEmbeddedEntity (I id ) {
26
+ this .id = id ;
27
+ }
28
+
29
+ @ EmbeddedId
30
+ public I getId () {
31
+ return id ;
32
+ }
33
+
34
+ public void setId (I id ) {
35
+ this .id = id ;
36
+ }
37
+
38
+ @ Override
39
+ public int hashCode () {
40
+ int hash = 3 ;
41
+ hash = 47 * hash + (this .id != null ? this .id .hashCode () : 0 );
42
+ return hash ;
43
+ }
44
+
45
+ @ Override
46
+ public boolean equals (Object obj ) {
47
+ if (this == obj ) {
48
+ return true ;
49
+ }
50
+ if (obj == null ) {
51
+ return false ;
52
+ }
53
+ if (getClass () != obj .getClass ()) {
54
+ return false ;
55
+ }
56
+ final BaseEmbeddedEntity <?> other = (BaseEmbeddedEntity <?>) obj ;
57
+ if (this .id != other .id && (this .id == null || !this .id .equals (other .id ))) {
58
+ return false ;
59
+ }
60
+ return true ;
61
+ }
62
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Hibernate, Relational Persistence for Idiomatic Java
3
+ *
4
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5
+ * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6
+ */
7
+ package org .hibernate .jpa .test .metamodel ;
8
+
9
+ import org .hibernate .jpa .test .BaseEntityManagerFunctionalTestCase ;
10
+ import org .hibernate .testing .TestForIssue ;
11
+ import org .junit .Test ;
12
+
13
+ import javax .persistence .EntityManager ;
14
+ import javax .persistence .metamodel .EmbeddableType ;
15
+ import javax .persistence .metamodel .EntityType ;
16
+ import javax .persistence .metamodel .ManagedType ;
17
+ import javax .persistence .metamodel .SingularAttribute ;
18
+
19
+ import static org .junit .Assert .*;
20
+
21
+ /**
22
+ * @author Christian Beikov
23
+ */
24
+ @ TestForIssue ( jiraKey = "HHH-11540" )
25
+ public class GenericsTest extends BaseEntityManagerFunctionalTestCase {
26
+ @ Override
27
+ public Class [] getAnnotatedClasses () {
28
+ return new Class [] {
29
+ Person .class ,
30
+ PersonId .class
31
+ };
32
+ }
33
+
34
+ @ Test
35
+ public void testEmbeddableTypeExists () {
36
+ EntityManager em = getOrCreateEntityManager ();
37
+ EmbeddableType <PersonId > idType = em .getMetamodel ().embeddable ( PersonId .class ) ;
38
+ assertNotNull ( idType );
39
+ em .close ();
40
+ }
41
+
42
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Hibernate, Relational Persistence for Idiomatic Java
3
+ *
4
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5
+ * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6
+ */
7
+ package org .hibernate .jpa .test .metamodel ;
8
+
9
+ import javax .persistence .Entity ;
10
+
11
+ /**
12
+ * @author Christian Beikov
13
+ */
14
+ @ Entity
15
+ public class Person extends BaseEmbeddedEntity <PersonId > {
16
+
17
+ private String firstName ;
18
+ private String lastName ;
19
+
20
+ public Person () {
21
+ }
22
+
23
+ public Person (PersonId id , String firstName , String lastName ) {
24
+ super (id );
25
+ this .firstName = firstName ;
26
+ this .lastName = lastName ;
27
+ }
28
+
29
+ public String getFirstName () {
30
+ return firstName ;
31
+ }
32
+
33
+ public void setFirstName (String firstName ) {
34
+ this .firstName = firstName ;
35
+ }
36
+
37
+ public String getLastName () {
38
+ return lastName ;
39
+ }
40
+
41
+ public void setLastName (String lastName ) {
42
+ this .lastName = lastName ;
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Hibernate, Relational Persistence for Idiomatic Java
3
+ *
4
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5
+ * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6
+ */
7
+ package org .hibernate .jpa .test .metamodel ;
8
+
9
+ import java .io .Serializable ;
10
+ import javax .persistence .Embeddable ;
11
+
12
+ /**
13
+ * @author Christian Beikov
14
+ */
15
+ @ Embeddable
16
+ public class PersonId implements Serializable {
17
+
18
+ private String ssn ;
19
+ private String name ;
20
+
21
+ public PersonId () {
22
+ }
23
+
24
+ public PersonId (String ssn , String name ) {
25
+ this .ssn = ssn ;
26
+ this .name = name ;
27
+ }
28
+
29
+ public String getSsn () {
30
+ return ssn ;
31
+ }
32
+
33
+ public void setSsn (String ssn ) {
34
+ this .ssn = ssn ;
35
+ }
36
+
37
+ public String getName () {
38
+ return name ;
39
+ }
40
+
41
+ @ Override
42
+ public int hashCode () {
43
+ int hash = 7 ;
44
+ hash = 67 * hash + (this .ssn != null ? this .ssn .hashCode () : 0 );
45
+ hash = 67 * hash + (this .name != null ? this .name .hashCode () : 0 );
46
+ return hash ;
47
+ }
48
+
49
+ @ Override
50
+ public boolean equals (Object obj ) {
51
+ if (this == obj ) {
52
+ return true ;
53
+ }
54
+ if (obj == null ) {
55
+ return false ;
56
+ }
57
+ if (getClass () != obj .getClass ()) {
58
+ return false ;
59
+ }
60
+ final PersonId other = (PersonId ) obj ;
61
+ if ((this .ssn == null ) ? (other .ssn != null ) : !this .ssn .equals (other .ssn )) {
62
+ return false ;
63
+ }
64
+ if ((this .name == null ) ? (other .name != null ) : !this .name .equals (other .name )) {
65
+ return false ;
66
+ }
67
+ return true ;
68
+ }
69
+
70
+ public void setName (String name ) {
71
+ this .name = name ;
72
+ }
73
+ }
You can’t perform that action at this time.
0 commit comments