Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cepr0/pg-uuid-projection-exception
Native query method with UUID and projection on PostgreSQL throws an exception
https://github.com/cepr0/pg-uuid-projection-exception
native-query postgresql projection spring-boot spring-data-jpa
Last synced: 3 days ago
JSON representation
Native query method with UUID and projection on PostgreSQL throws an exception
- Host: GitHub
- URL: https://github.com/cepr0/pg-uuid-projection-exception
- Owner: Cepr0
- Created: 2018-04-25T20:56:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-26T10:12:46.000Z (over 6 years ago)
- Last Synced: 2024-11-17T02:42:24.316Z (2 months ago)
- Topics: native-query, postgresql, projection, spring-boot, spring-data-jpa
- Language: Java
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Native query method with **projection** containing **UUID** properties throws an exception:
> org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
(tested on **PostgreSQL**)
Example:
```java
@Entity
public class Model {@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
private UUID uuid;
}@Query(value = "select m.id as id, m.uuid as uuid from model m where m.id = ?1", nativeQuery = true)
Optional getModelProjection(UUID id);
```Native query with entity class works as expected.
How to reproduce:
1. Create database `uuid-demo` in PostgreSQL server (with username and password `postgres` - see 'application.properties')
2. Run test `io.github.cepr0.demo.ModelRepoTest`To workaround this I created a custom PostgreSQL dialect class:
```java
public class CustomPostgreSQL95Dialect extends PostgreSQL95Dialect {
public PatchedPostgreSQL95Dialect() {
super();
registerHibernateType(Types.OTHER, "org.hibernate.type.PostgresUUIDType");
}
}
```And set it in the 'application.properties'
`spring.jpa.properties.hibernate.dialect=io.github.cepr0.demo.CustomPostgreSQL95Dialect`
P.S. During testing, it turned out that [class-based projections](https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections.dtos)
does not work with native queries - they throw an exception:```
org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap]
to type [io.github.cepr0.demo.ModelDto]
```