[Solved] Sharding-Proxy Insert Datas Error: Sharding value must implements Comparable NoSuchElementException

data insertion error
1. After doing sub-database and sub-table, it is now necessary to migrate the existing data of a single database to the corresponding sub-database and sub-table database
2. Data migration is to read the table structure information of the specified table, use 3. PreparedStatement, and use placeholders to splicing and submitting data
3. In order to prevent migration errors, migrate multiple times, clear the sharding table each time, and then migrate
4. During the migration, some errors were encountered, version 5.0

Report an error

Sharding value must implements Comparable

CommandExecutorTask - Exception occur: 
java.lang.IllegalArgumentException: Sharding value must implements Comparable.

Causes and Solutions

1. A non-null field with a null value inserted
2. It may be the primary key. If the primary key policy is not set and it is not automatically generated, an error will be reported.
3. It may be the sub-database sub-table key, which cannot be null. This is my situation, the data is maintained, and the sub-database fields of all tables are assigned corresponding values, and the error is resolved

Error report 2

NoSuchElementException

org.postgresql.util.PSQLException: ERROR: java.util.NoSuchElementException

Causes and Solutions

1. The reason is that the number of inserted values ​​does not match the number of table fields.
2. The first time I encountered this error, it was due to the use of sub-database sub-table and data encryption at the same time
3. The field configuration of data encryption affects the calculation and reading of the number of fields, resulting in the mismatch between fields and inserted values, resulting in an error. 4.  After temporarily dropping the data encryption,Solved
4. The second time I encountered this error, I found that the structure of the original table was changed, and 2 fields were added. The table structure of the sub-database and sub-tables has not changed, resulting in the field value and quantity not corresponding to each other. Maintain the table structure of the sub-database and sub-tables After that, solve it (the problem is that after adding the field, it will not take effect without restarting sharding-proxy)

Read More: