I am facing issue in saving string values in one of the fields of my domain
My Domain is
#Entity
#Table(name = "users")
class User {
#Id
#NotNull
Long id
#NotNull
String uuid
#NotNull
String firstName
}
I am pulling the data from my main mysql database and saving it into another database.
resultSet = statement.executeQuery(userQuery)
while (resultSet.next()) {
User user = new User()
user.id = resultSet.getLong("a.id")
user.uuid = resultSet.getString("a.uuid")
user.firstName = resultSet.getString("b.first_name") // exception occurs here
userRepository.save(user)
}
Some of my data is getting saved but when data from my main database contains user with
firstname = ऋषभ (Name in Hindi Language) then it throws exception.
Note - Only essential codes i mentioned here query execution database connection everything is running fine only facing issue in setting data in user.firstName only when my query result contains string with different language.
ALTER TABLE user MODIFY first_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
my mysql does not display Polish characters and I created the database like this:
CREATE DATABASE mydb
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
The problem is on the side of entity-framework, because I called it using the Seed method from Migration, when everything is added using the controller everything is ok, I tried to insert SQL into ordinary SQL and it worked
This not working:
protected override void Seed(WebApplication2.Context context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data.
context.Persons.Add(new Person { Age = 19, LastName = "ćżół", Name = "Sławek" });
});
}
I have successfully implemented Ignited-Datatables. However, while searching with database when typing "non-latin" characters like "İ,ş,ğ,.."
POST http://vproject.dev/module/user/ign_listing 500 (Internal Server Error)
Details are:
Illegal mix of collations for operation 'like' while searching
... (u.id_user LIKE '%Ä°%' OR u.first_name LIKE '%Ä°%' OR u.last_name LIKE '%Ä°%' OR ue.email LIKE '%Ä°%' OR u.last_login LIKE '%Ä°%' ) ...
%Ä°% part changes according to the non-latin character you typed.
Any idea for solving this?
I figured out the problem. It seems it is DATETIME fields that causes the problem.
.. ue.last_login '%ayşenur%'
gives error for Illegal mix of collations for operation 'like'. When I remove LIKE partials DATETIME fields, there are no error any more. I hope this helps.
Try the following:
u.id_user LIKE '%Ä°%' OR ... OR ... '%Ä°%' COLLATE utf8_bin
Refer to MySQL Unicode Character Sets
Also you can refer to MySQL _bin and binary Collations for more information on utf8_bin:
Nonbinary strings (as stored in the CHAR, VARCHAR, and TEXT data
types) have a character set and collation. A given character set can
have several collations, each of which defines a particular sorting
and comparison order for the characters in the set. One of these is
the binary collation for the character set, indicated by a _bin suffix
in the collation name. For example, latin1 and utf8 have binary
collations named latin1_bin and utf8_bin.
The question is a little bit old.
Finally I find a solution change "LIKE " TO "LIKE binary "
I was having the same problem in Datatable search ssp.class.php
i solved by converting to UTF8 like :
CONVERT(`user_datetime` USING utf8)
fix in ssp.class.php:
$globalSearch[] = "CONVERT(`".$column['db']."` USING utf8) LIKE ".$binding;
My final code was :
static function filter ( $request, $columns, &$bindings )
{
$globalSearch = array();
$columnSearch = array();
$dtColumns = self::pluck( $columns, 'dt' );
if ( isset($request['search']) && $request['search']['value'] != '' ) {
$str = $request['search']['value'];
for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
$requestColumn = $request['columns'][$i];
$columnIdx = array_search( $requestColumn['data'], $dtColumns );
$column = $columns[ $columnIdx ];
if ( $requestColumn['searchable'] == 'true' ) {
$binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
$globalSearch[] = "CONVERT(`".$column['db']."` USING utf8) LIKE ".$binding;
}
}
}
i know that this is far too late, but, here my workaround.
SELECT * FROM (SELECT DATE_FORMAT(some_date,'%d/%m/%Y') AS some_date FROM some_table)tb1
WHERE some_date LIKE '% $some_variable %'
datetime/date column gives error for Illegal mix of collations for operation 'like', therefore, by converting it, as another table entity, previous column type will be replace with varchar type.
also, make sure to convert any column before convert it to temporary table, to make matching process more easier.
I met a similar error when LIKE was applied to the DateTime column.
So now, instead of using simple date_col LIKE '2019%' I use CAST(date_col AS CHAR) LIKE '2019%'.
The solution was found on the official MySQL bugs website.
I am getting an Incorrect string value (Exception Value: Incorrect string value: '\xEA\xB0\x95\xED\x95\x98...' for column 'object_repr' at row 1) error while trying to save unicode string (Korean) in Django and MySQL.First problem I had was "Incorrect string value" error for each column in the database table. However, I figured this out by changing column collation and overall database character set.
The new error I am getting is related to unicode(self) method in models.py.My models.py is as the following:
from django.db import models
# Create your models here.
class User(models.Model):
full_name = models.CharField(max_length=60)
email = models.EmailField(unique=True)
password = models.CharField(max_length=128)
birthday = models.DateField(null=True, blank=True)
gender = models.PositiveIntegerField(null=True, blank=True)
location = models.CharField(max_length=60, null=True, blank=True)
captcha = models.CharField(max_length=60, null=True, blank=True)
register_date = models.DateTimeField()
lastLogin_date = models.DateTimeField(null=True)
num_logins = models.PositiveIntegerField()
def __unicode__(self):
return self.full_name
The error is generated when the__unicode__ function tries to output utf8 character...
Does anybody know how to fix this error?
In MySQL console execute
ALTER DATABASE django_db CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE django_admin_log MODIFY object_repr VARCHAR(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
For me it helps.
Try add one line on the first of this file like this:
#-*- encoding=UTF-8 -*-
I solved this problem by changing the file settings.py: Don´t use 'ENGINE': 'django.db.backends.mysql'.
I have Login Table that have utf8 charset and utf8 collation when I want check user name and retrieve other information for this specific user name the hql query give me the same result with lowercase and uppercase.
what should l do for my HQL query that work case sesitive
I use Mysql 5 and java hibernarte
this is my query:
return queryManager.executeQueryUniqueResult("select b.login from BranchEntity b where b.userName = ?", username);
The easiest way is to change your column's definition to use case-insensitive collation like utf8_bin.
Details are here
Add class
public class CollateDialect extends MySQLDialect {
#Override
public String getTableTypeString() {
return " COLLATE utf8_bin";
}
}
and use it:
cfg.setProperty("hibernate.dialect", "org.kriyak.hbm.CollateDialect");
this will make all queries case-sensitive that makes much more sence.