Skip to content

Commit c9805f2

Browse files
yrodierebeikov
authored andcommitted
HHH-17683 Reproducer for jpamodelgen generating wrong constructor for metamodel of entities whose methods contain a static EntityManager getEntityManager()
1 parent 18b1cea commit c9805f2

18 files changed

+683
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
11+
@Entity
12+
public class EntityExtendingEntityWithInstanceGetEntityManager extends EntityWithInstanceGetEntityManager {
13+
private String otherName;
14+
15+
public String getOtherName() {
16+
return otherName;
17+
}
18+
19+
public void setOtherName(String otherName) {
20+
this.otherName = otherName;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
11+
@Entity
12+
public class EntityExtendingEntityWithStaticGetEntityManager extends EntityWithStaticGetEntityManager {
13+
private String otherName;
14+
15+
public String getOtherName() {
16+
return otherName;
17+
}
18+
19+
public void setOtherName(String otherName) {
20+
this.otherName = otherName;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
11+
@Entity
12+
public class EntityExtendingMapperSuperClassExtendingNonEntityWithInstanceGetEntityManager
13+
extends MapperSuperClassExtendingNonEntityWithInstanceGetEntityManager {
14+
15+
private String name;
16+
17+
public String getName() {
18+
return name;
19+
}
20+
21+
public void setName(String name) {
22+
this.name = name;
23+
}
24+
25+
private String otherName;
26+
27+
public String getOtherName() {
28+
return otherName;
29+
}
30+
31+
public void setOtherName(String otherName) {
32+
this.otherName = otherName;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
11+
@Entity
12+
public class EntityExtendingMapperSuperClassExtendingNonEntityWithStaticGetEntityManager
13+
extends MapperSuperClassExtendingNonEntityWithStaticGetEntityManager {
14+
15+
private String name;
16+
17+
public String getName() {
18+
return name;
19+
}
20+
21+
public void setName(String name) {
22+
this.name = name;
23+
}
24+
25+
private String otherName;
26+
27+
public String getOtherName() {
28+
return otherName;
29+
}
30+
31+
public void setOtherName(String otherName) {
32+
this.otherName = otherName;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
11+
@Entity
12+
public class EntityExtendingMapperSuperClassWithInstanceGetEntityManager
13+
extends MapperSuperClassWithInstanceGetEntityManager {
14+
15+
private String name;
16+
17+
public String getName() {
18+
return name;
19+
}
20+
21+
public void setName(String name) {
22+
this.name = name;
23+
}
24+
25+
private String otherName;
26+
27+
public String getOtherName() {
28+
return otherName;
29+
}
30+
31+
public void setOtherName(String otherName) {
32+
this.otherName = otherName;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
11+
@Entity
12+
public class EntityExtendingMapperSuperClassWithStaticGetEntityManager
13+
extends MapperSuperClassWithStaticGetEntityManager {
14+
15+
private String name;
16+
17+
public String getName() {
18+
return name;
19+
}
20+
21+
public void setName(String name) {
22+
this.name = name;
23+
}
24+
25+
private String otherName;
26+
27+
public String getOtherName() {
28+
return otherName;
29+
}
30+
31+
public void setOtherName(String otherName) {
32+
this.otherName = otherName;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
import jakarta.persistence.Id;
11+
12+
@Entity
13+
public class EntityExtendingNonEntityWithInstanceGetEntityManager extends NonEntityWithInstanceGetEntityManager {
14+
@Id
15+
private Long id;
16+
private String name;
17+
18+
public Long getId() {
19+
return id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public String getName() {
27+
return name;
28+
}
29+
30+
public void setName(String name) {
31+
this.name = name;
32+
}
33+
34+
private String otherName;
35+
36+
public String getOtherName() {
37+
return otherName;
38+
}
39+
40+
public void setOtherName(String otherName) {
41+
this.otherName = otherName;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
import jakarta.persistence.Id;
11+
12+
@Entity
13+
public class EntityExtendingNonEntityWithStaticGetEntityManager extends NonEntityWithStaticGetEntityManager {
14+
@Id
15+
private Long id;
16+
private String name;
17+
18+
public Long getId() {
19+
return id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public String getName() {
27+
return name;
28+
}
29+
30+
public void setName(String name) {
31+
this.name = name;
32+
}
33+
34+
private String otherName;
35+
36+
public String getOtherName() {
37+
return otherName;
38+
}
39+
40+
public void setOtherName(String otherName) {
41+
this.otherName = otherName;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
import jakarta.persistence.EntityManager;
11+
import jakarta.persistence.Id;
12+
import jakarta.persistence.Transient;
13+
14+
@Entity
15+
public class EntityWithInstanceGetEntityManager {
16+
17+
@Transient
18+
public EntityManager getEntityManager() {
19+
// In a real-world scenario, this would contain some framework-specific code
20+
throw new IllegalStateException( "This method shouldn't be called in tests" );
21+
}
22+
23+
@Id
24+
private Long id;
25+
private String name;
26+
private String entityManager;
27+
28+
public Long getId() {
29+
return id;
30+
}
31+
32+
public void setId(Long id) {
33+
this.id = id;
34+
}
35+
36+
public String getName() {
37+
return name;
38+
}
39+
40+
public void setName(String name) {
41+
this.name = name;
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.jpamodelgen.test.constructor;
8+
9+
import jakarta.persistence.Entity;
10+
import jakarta.persistence.EntityManager;
11+
import jakarta.persistence.Id;
12+
13+
@Entity
14+
public class EntityWithStaticGetEntityManager {
15+
16+
public static EntityManager getEntityManager() {
17+
// In a real-world scenario, this would contain some framework-specific code
18+
throw new IllegalStateException( "This method shouldn't be called in tests" );
19+
}
20+
21+
@Id
22+
private Long id;
23+
private String name;
24+
25+
public Long getId() {
26+
return id;
27+
}
28+
29+
public void setId(Long id) {
30+
this.id = id;
31+
}
32+
33+
public String getName() {
34+
return name;
35+
}
36+
37+
public void setName(String name) {
38+
this.name = name;
39+
}
40+
41+
}

0 commit comments

Comments
 (0)