# Hibernate 6 migration, get hibernate type from string class name or primitive type

**URL:** <https://discourse.hibernate.org/t/hibernate-6-migration-get-hibernate-type-from-string-class-name-or-primitive-type/7593>\
**Category:** Hibernate ORM\
**Created:** [May 3, 2023, 3:47pm UTC](https://discourse.hibernate.org/t/hibernate-6-migration-get-hibernate-type-from-string-class-name-or-primitive-type/7593 "2023-05-03T15:47:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amir](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/amir/32/2415_2.png) [@amir](https://discourse.hibernate.org/u/amir)\
**Post date:** [May 3, 2023, 3:47pm UTC](https://discourse.hibernate.org/t/hibernate-6-migration-get-hibernate-type-from-string-class-name-or-primitive-type/7593/1 "2023-05-03T15:47:27Z")

</div>

Hi there,  
I have in the project code that seems to be written back in 2019…not sure what version of hibernate was used at that point… now i’m trying to upgrade to new spring boot and hibernate and I see the code

```auto
                TypeConfiguration typeConfiguration = new TypeConfiguration();
                TypeFactory typeFactory = new TypeFactory(typeConfiguration);
                TypeLocatorImpl typeLocator = new TypeLocatorImpl(new TypeResolver(typeConfiguration, typeFactory));
            Type myType 
............. if(....)
                Type myType = typeLocator.entity(valueClass);
              .........
                myType = typeLocator.basic(basicJavaType);

```

I don’t see those classes anymore in hibernate 6 and can’t find any docs suggesting replacement…  
Can you please give me some hints ?  
In the end I need a way to get hibernate “Type” from entity class which is string, or type from java primitive type like String, Long etc

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 4, 2023, 9:45am UTC](https://discourse.hibernate.org/t/hibernate-6-migration-get-hibernate-type-from-string-class-name-or-primitive-type/7593/2 "2023-05-04T09:45:44Z")

</div>

Did you read the migration guides?

- [hibernate-orm/migration-guide.adoc at 6.0 · hibernate/hibernate-orm · GitHub](https://github.com/hibernate/hibernate-orm/blob/6.0/migration-guide.adoc)
- [hibernate-orm/migration-guide.adoc at 6.1 · hibernate/hibernate-orm · GitHub](https://github.com/hibernate/hibernate-orm/blob/6.1/migration-guide.adoc)
- [hibernate-orm/migration-guide.adoc at 6.2 · hibernate/hibernate-orm · GitHub](https://github.com/hibernate/hibernate-orm/blob/6.2/migration-guide.adoc)

---

<div class="post-metadata">

**Author:** ![amir](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/amir/32/2415_2.png) [@amir](https://discourse.hibernate.org/u/amir)\
**Post date:** [May 4, 2023, 2:43pm UTC](https://discourse.hibernate.org/t/hibernate-6-migration-get-hibernate-type-from-string-class-name-or-primitive-type/7593/3 "2023-05-04T14:43:03Z")

</div>

Thanks for posting this. Yes I’ve seen it, it didn’t provide the answer what to use instead of missing classes or what API to use to get hibernate Type  
So if you can share some examples it would be nice…  
I think I found some workarounds but I wasn’t an author of original code so I’m not sure if my workaround will work in any case, but at least my code compiles now and I’m able to run tests…

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 9, 2023, 9:16am UTC](https://discourse.hibernate.org/t/hibernate-6-migration-get-hibernate-type-from-string-class-name-or-primitive-type/7593/4 "2023-05-09T09:16:22Z")

</div>

You can use `org.hibernate.engine.spi.SessionFactoryImplementor#getMappingMetamodel` to access the entity mapping types. Accessing basic types can be done through `org.hibernate.engine.spi.SessionFactoryImplementor#getTypeConfiguration` by using e.g. the `standardBasicTypeForJavaType` methods.

---

<div class="post-metadata">

**Author:** ![amir](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/amir/32/2415_2.png) [@amir](https://discourse.hibernate.org/u/amir)\
**Post date:** [May 10, 2023, 11:38am UTC](https://discourse.hibernate.org/t/hibernate-6-migration-get-hibernate-type-from-string-class-name-or-primitive-type/7593/5 "2023-05-10T11:38:29Z")

</div>

Yeah, thanks, I think I can get what logics needs
