# How to implement EnhancedUserType

**URL:** <https://discourse.hibernate.org/t/how-to-implement-enhancedusertype/3943>\
**Category:** Hibernate ORM\
**Created:** [March 26, 2020, 12:29pm UTC](https://discourse.hibernate.org/t/how-to-implement-enhancedusertype/3943 "2020-03-26T12:29:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thmayr](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@thmayr](https://discourse.hibernate.org/u/thmayr)\
**Post date:** [March 26, 2020, 12:29pm UTC](https://discourse.hibernate.org/t/how-to-implement-enhancedusertype/3943/1 "2020-03-26T12:29:03Z")

</div>

Hello Hibernate People,

I implemented a custom user type to map boolean values to database values. When I execute a query with the following criteria, I get an exception, that tells me that the user type cannot be casted to _EnhancedUserType_:

```auto
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
...
criteriaBuilder.isTrue(root.get("imported"))

```

The _imported_ property is a boolean value mapped with this user type.

However, when I change the criteria using _equal()_ instead of _isTrue()_ it works:

```auto
criteriaBuilder.equal(root.get("imported"), true))

```

So I have the following questions:

1. Why do I need to implement _EnhancedUserType_ when I use _isTrue()_?
2. Is there an advise how to implement the interface _EnhancedUserType_ correctly?
3. Two methods of this interface are deprecated. Does this mean, that this methods are not called by Hibernate anymore and may return null?
4. I found some articles, which implement the method _objectToSQLString()_ so that it returns the string value enclosed in single quotes. Is this the right way to do it?

Unfortunately the JavaDocs of this interface is not very helpful.

Kind regards  
Thomas Mayr
