Order Strings with polish in Postgres - java

What is the best way to order Entities by some String field that contains polish letters?
Is there a way to do that with Spring Data? Can I include Locale into Pageabe for this?:
Page<Collection> findByInstitutionIdAndIsDeletedFalse(Long institutionId, Pageable pageable);
and
Sort.Order entityOrder = Sort.Order.by("title").ignoreCase();
PageRequest pageable = PageRequest.of(page, perPage, Sort.by(entityOrder));
When I do like that, I have:
alaska
lalka
termos
łóżko
But "łóżko" should be after "lalka".
I tried to change Locale in Postgres database, but it didn't work for db1 nor db2.
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
db1 | user | UTF8 | pl_PL | pl_PL |
db2 | user | UTF8 | pl_PL.utf8 | pl_PL.utf8 |
db3 | user | UTF8 | en_US.utf8 | en_US.utf8 |
Thanks for any suggestions!

Ok, I've changed postgres version from alpine to 9.6, and in Dockerfile I have these lines:
RUN localedef -i pl_PL -c -f UTF-8 -A /usr/share/locale/locale.alias pl_PL.UTF-8
ENV LANG PL_PL.utf8
ENV LC_ALL="pl_PL.UTF-8"
ENV LC_CTYPE="pl_PL.UTF-8"
Now It's working and I have right order. But still I'am wondering how to build my postgres from docker-compose file.

Related

ERROR 1366 (HY000): Incorrect string value: '\x85\x8A\x8D\x95\x97' for column 'name' at row 1

this is the faulty statement:
insert into customer (id, uuid, name) values (1,uuid(), 'àèìòù');
I am using MySQL server 8.0.32 (just upgraded from 5.7) on Windows.
I am also executing this statement from MySQL client, on the same machine.
Same error using mysql-connector-j-8.0.32.
jdbc:mysql://localhost:3306/risk?allowPublicKeyRetrieval=true&useLocalSessionState=true&rewriteBatchedStatements=true
No error using mysql-connector-java-8.0.22 with the same environment and the same connection string.
This the table:
| customer | CREATE TABLE `customer` (
`id` bigint NOT NULL,
`uuid` char(36) NOT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_q8w2f8xfdoax44qc8w0epholu` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
And these are the variables:
mysql> show variables like '%char%';
+--------------------------+------------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8mb3 |
| character_sets_dir | D:\shape\servers\mysql-8.0.32-winx64\share\charsets\ |
+--------------------------+------------------------------------------------------+
8 rows in set (0.00 sec)
mysql> show variables like '%collation%';
+-------------------------------+--------------------+
| Variable_name | Value |
+-------------------------------+--------------------+
| collation_connection | utf8mb4_0900_ai_ci |
| collation_database | utf8mb4_0900_ai_ci |
| collation_server | utf8mb4_0900_ai_ci |
| default_collation_for_utf8mb4 | utf8mb4_0900_ai_ci |
+-------------------------------+--------------------+
4 rows in set (0.00 sec)
Maybe a bug? Am I missing something?
update
this is working:
mysql> set character_set_client=cp850;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into customer (id, uuid, name) values (1,uuid(), 'àèìòù');
Query OK, 1 row affected (0.00 sec)
But why?
And how can I use UTF-8 also on client side?
update2
Also, commenting in my.ini:
character-set-server=utf8mb4
collation-server=utf8mb4_0900_ai_ci
#character-set-client-handshake = FALSE
#init_connect='SET NAMES utf8mb4'
makes JDBC working again...
What application are you using?
Apparently, your client is using "cp850" since that hex decodes to àèìòù.
You could either tell MySQL that you are using cp850 by establishing the connection that way, or (better) fix the encoding inside the client.
That is, the problem does not seem to be with MySQL.
More
If you are using Windows, did you do something like
chcp 850
Instead, you need
chcp 65001

Calling/mapping another entity in getter with hibernate

Consider this simple database schema:
User Relation Property
+-------------+ +--------------+ +---------------+
| -user_id | | -relation_id | | -property_id |
| | | -source_id | | |
| | | -target_id | | |
| | | -type | | |
+-------------+ +--------------+ +---------------+
The relation table contains multiple source and target ids (as STRING) from another tables and "connect" dynamically difficult types of entities. So the source_id can be a user_id and target_id property_id, but also other entities and vice versa.
Now I want in User the properties over the relation table when type is property.
#OneToMany(mappedBy = "source", fetch = FetchType.EAGER)
#Where(clause = "type = 'PROPERTY'")
#ElementCollection
private Set<Relation> properties;
This works perfectly fine. I receive the relation entity with the property id as string in target_id.
Is it possible to resolve this and extend the getter, so that i receive the real property entity?
Like calling the propertyRepository within the user entity. As a newbie in java and jpa/hibernate im a bit lost here.

Invalid string value: '\ xD0...." for the column .... ". utf8 charset try used

In the spring project, I try to introduce Cyrillic characters into the database. But the database does not encode it.
I used the extended JpaRepository interface, method save (T t), and everything works correctly when I send English text;
when the program tries to save the entity with the Cyrillic, I get the exception "Invalid string value: '\ xD0 \ xA5 \ xD0 \ xB0 \ xD0 \ xB1 ..." for the column .... "
So encoding does not work.
My database character variables:
application.properties:
launchMode=cli
#Database settings
spring.datasource.url=jdbc:mysql://localhost:3306/mySecondBD?serverTimezone=UTC
spring.jpa.hibernate.ddl-auto=update
spring.datasource.username=root
spring.datasource.password=password
#spring.datasource.driver-class-name=org.gjt.mm.mysql.Driver
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8;
spring.datasource.sql-script-encoding=UTF-8
Question:
Where more I need set charset encoding params?
Edit properties :
spring.datasource.url=jdbc:mysql://localhost:3306/mySecondBD?useUnicode=yes&characterEncoding=UTF-8
Check your variables :
mysql> show variables like 'char%';
Edit my.cnf :
vi /etc/my.cnf
[client]
default-character-set=utf8
Finally, you recheck your MySQL variables and confirm your query result.
Hex D0A5D0B0D0B1 is the UTF-8 encoding for Cyrillic Хаб. So, using MySQL's utf8 (or utf8mb4) should work.
When you said '\ xD0 \ xA5 \ xD0 \ xB0 \ xD0 \ xB1 ...", you had extra spaces; were they in the output you saw?
Please provide SHOW CREATE TABLE page.
Somehow, you need to say that the client encoding is utf8. One way (in spring) is to put this in the application.yml:
datasource:
connectionInitSql: "SET NAMES 'utf8'"
Used this query , it works for me...
ALTER TABLE table_name MODIFY COLUMN column_name varchar(255)
CHARACTER SET utf8 COLLATE utf8_general_ci;
In summary, I do next steps and all runs:
edit application.properties, how me advised
spring.datasource.url=jdbc:mysql://localhost:3306/mySecondBD?useUnicode=yes&characterEncoding=UTF-8
changed own my table encode property(not only database):
ALTER TABLE page CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE page CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
and I changed variable column into text:
alter TABLE page MODIFY content TEXT(21844);
PS variables of the database:
| Variable_name | Value |
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |

Vaadin: how to set up relation between two SQLContainers?

I have two SQLContainers with the folowing data structure:
SQLContainer SP:
FullUserName | tel | room
SQLContainer MT:
FullUserName | ComputerName | Domain | OS
In my opinion, the foreign key of the both SQLContainers could be: "FullUserName" field?!
How can i set relation (reference) between these containers to get the finally view like this:
FullUserName | tel | room | ComputerName | Domain | OS
?

Set any field once for all the tests in Fitnesse table

I want to set one field in the fitnesse table, only once for all the tests. For example I want to set Operator as + for all the tests in the table.
Below is the regular table.
!|CalculatorFixture |
|Value1|Operator|Value2|calculate?|
|3.0 |+ |5.0 |8.0 |
|2.0 |* |3.5 |7.0 |
I want something like:
!| CalculatorFixture |
|Operator |
|+ |
|Value1|Value2|calculate?|
|3.0 |5.0 |8.0 |
|6.0 |3.0 |9.0 |
|5.0 |2.0 |7.0 |
Any Idea how can I achieve this in the fixture or in the fitnesse table?
FYI, I am using Slim: !define TEST_SYSTEM {slim}
You can set a Java static field in a previous table fixture and then access it in the CalculatorFixture.
You can also pass 'constructor parameters' to scenarios by using having or given as first cell after the scenario name (from FitNesse's tests)
|scenario | myDivision _ _ _|numerator, denominator, quotient|
|setNumerator | #numerator |
|setDenominator | #denominator|
|check | quotient| #quotient |
| myDivision | having |numerator| 12|
| denominator|quotient|
| 3 |4.0 |
| 6 |2.0 |
| 4 |3.0 |

Categories