# Hibernate access to PostgreSQL custom data types

**URL:** <https://discourse.hibernate.org/t/hibernate-access-to-postgresql-custom-data-types/1805>\
**Category:** Hibernate ORM\
**Created:** [November 28, 2018, 7:34am UTC](https://discourse.hibernate.org/t/hibernate-access-to-postgresql-custom-data-types/1805 "2018-11-28T07:34:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anuchatu](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anuchatu](https://discourse.hibernate.org/u/anuchatu)\
**Post date:** [November 28, 2018, 7:34am UTC](https://discourse.hibernate.org/t/hibernate-access-to-postgresql-custom-data-types/1805/1 "2018-11-28T07:34:11Z")

</div>

Hello Team,

We are looking for your help on the below given issue.

Issue: We have created one custom data type in PostGreSQL database as given below:

CREATE TYPE temporal as (  
start\_date timestamp,  
end\_date timestamp  
);

and this needs to be accessed by application using hibernate ORM, but concern is that we can’t select the any subtype (start\_date or end\_date) of temporal without using brackets () around custom data type as given below:

Create table testTemporal temporal\_date temporal;

Select (temporal\_date).start\_date from testTemporal;

When we are trying to access start\_date column using latest JPA/HIbernate version, it is not generating the queries without brackets around temporal\_date like (temporal\_date.start\_date), which is throwing SQL Exception by saying that temporal\_date is no table found in database. ( We are not using any native queries).

so please advise how to handle such scenario?

Anticipating a reply soon.

Regards  
Anurag

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [November 28, 2018, 1:11pm UTC](https://discourse.hibernate.org/t/hibernate-access-to-postgresql-custom-data-types/1805/2 "2018-11-28T13:11:10Z")

</div>

When it comes to mapping such type, you could try to write a `CompositeType` to support this `temporal` custom type.

However, you won’t be able to reference individual columns in JPQL queries. You could only do that with native SQL.

So, you are better off using an `Embeddable` on the Java side that maps to the `start_date` and `end_date` columns in your table. This way, you need the `start_date` and `end_date` columns to be added to the table instead of having them maped as a DB-specific type.

---

<div class="post-metadata">

**Author:** ![anuchatu](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anuchatu](https://discourse.hibernate.org/u/anuchatu)\
**Post date:** [November 28, 2018, 1:39pm UTC](https://discourse.hibernate.org/t/hibernate-access-to-postgresql-custom-data-types/1805/3 "2018-11-28T13:39:49Z")

</div>

Thanks Vlad for your response. Is there any plan to incorporate this feature in coming releases where custom types can be used by using JPQL?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [November 28, 2018, 2:35pm UTC](https://discourse.hibernate.org/t/hibernate-access-to-postgresql-custom-data-types/1805/4 "2018-11-28T14:35:42Z")

</div>

The query parser has been rewritten in 6.0, so only after releasing 6.0 we could try to investigate it. You could add a Jira issue for this.

---

<div class="post-metadata">

**Author:** ![anuchatu](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anuchatu](https://discourse.hibernate.org/u/anuchatu)\
**Post date:** [November 29, 2018, 6:13am UTC](https://discourse.hibernate.org/t/hibernate-access-to-postgresql-custom-data-types/1805/5 "2018-11-29T06:13:05Z")

</div>

Thanks for your quick response !!
