question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeConverter not used for inserting/updating type Object

See original GitHub issue

TypeConverters are working wonderfully for reading/querying and writing/inserting/updating data except for one case: when you’re trying to insert/update and expect a value to be converted before being bound to the statement.

You can see in this code where the problem is:

https://github.com/micronaut-projects/micronaut-data/blob/23075f01c2aa26ed23311c634e16abf6bcc239a0/data-runtime/src/main/java/io/micronaut/data/runtime/mapper/QueryStatement.java#L40

All other data types have a nice callout to convertRequired except for the Object. This means my TypeConvert doesn’t get utilized, resulting in a JDBC error. The specific use case is I’m trying to convert into JSONB type in Postgres. Interestingly, it works on queries because the code doesn’t even try to understand the underlying type, it simply passes all ResultSet values off to the type converters:

https://github.com/micronaut-projects/micronaut-data/blob/23075f01c2aa26ed23311c634e16abf6bcc239a0/data-runtime/src/main/java/io/micronaut/data/runtime/mapper/sql/SqlResultEntityTypeMapper.java#L229

I’ll see if I can get you a patch soon!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
zeariccommented, Mar 23, 2020

I have the similar issue when use a List of JsonType, e.g.

@TypeDef(type = DataType.JSON)
List<User> users;

Query and Create are ok. but got error when update this field to postgres DB: The column index is out of range I found a work around: create wrapper for the List, e.g

@TypeDef(type = DataType.JSON)
UserList users;

UserList is just a wrapper:

public class UserList{
   List<User> userList;
}

Hope this can help anyone has the same issue.

0reactions
mchmielarzcommented, Nov 10, 2021

Thanks @zearic for the tip. I still have the issue storing Map in JSONB column and have to use the workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Room Database TypeConverter is not used in some ...
My type converter uses a different delimiter, so the queries are not compatible! If the set is empty, the SQL string is not...
Read more >
TypeConverter Class (System.ComponentModel)
Provides a unified way of converting types of values to other types, as well as for accessing standard values and subproperties.
Read more >
Referencing complex data using Room - Android Developers
Use type converters. Control type converter initialization. Understand why Room doesn't allow object references.
Read more >
Type converters - Drift - Simon Binder
You can achieve this by using TypeConverters . ... If your converter returns an object that is not comparable by value, the generated...
Read more >
LLBLGen Pro SDK - Implementing a type converter.
LLBLGen Pro comes with a handy conversion functionality for conversion values at runtime: type converters. Type Converters are objects which can be used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found