Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Attribute#getJavaType() returs also primitive types
- Loading branch information
Showing
11 changed files
with
105 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...e/src/main/java/org/hibernate/metamodel/model/domain/internal/PrimitiveBasicTypeImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.metamodel.model.domain.internal; | ||
|
||
import org.hibernate.type.descriptor.java.JavaType; | ||
|
||
public class PrimitiveBasicTypeImpl<J> extends BasicTypeImpl<J> { | ||
private final Class<J> javaTypeClass; | ||
|
||
public PrimitiveBasicTypeImpl(JavaType<J> javaType, Class<J> javaTypeClass) { | ||
super( javaType ); | ||
assert javaTypeClass.isPrimitive(); | ||
this.javaTypeClass = javaTypeClass; | ||
} | ||
|
||
@Override | ||
public Class<J> getJavaType() { | ||
return javaTypeClass; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
hibernate-core/src/test/java/org/hibernate/orm/test/jpa/compliance/GetJavaTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.orm.test.jpa.compliance; | ||
|
||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; | ||
import org.hibernate.testing.orm.junit.Jpa; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.metamodel.Attribute; | ||
import jakarta.persistence.metamodel.ManagedType; | ||
import jakarta.persistence.metamodel.Metamodel; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@Jpa( | ||
annotatedClasses = GetJavaTypeTest.Person.class | ||
) | ||
public class GetJavaTypeTest { | ||
|
||
@Test | ||
public void getJavaType(EntityManagerFactoryScope scope) { | ||
scope.inEntityManager( | ||
entityManager -> { | ||
Metamodel metaModel = entityManager.getMetamodel(); | ||
if ( metaModel != null ) { | ||
ManagedType<Person> mTypeOrder = metaModel.managedType( Person.class ); | ||
assertNotNull( mTypeOrder ); | ||
Attribute<Person, ?> attrib = mTypeOrder.getDeclaredAttribute( "age" ); | ||
assertNotNull( attrib ); | ||
Class pAttribJavaType = attrib.getJavaType(); | ||
assertEquals( "int", pAttribJavaType.getName() ); | ||
} | ||
} | ||
); | ||
} | ||
|
||
@Entity(name = "Person") | ||
@Table(name = "PERSON_TABLE") | ||
public static class Person { | ||
@Id | ||
private int id; | ||
|
||
private String name; | ||
|
||
private int age; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters