Currently i tried by modifying my property file to insert those special characters.But its inserting as a question mark instead of ₹ Symbol please find below changes.
spring.datasource.url=jdbc:mysql://localhost:3306/dbName?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&useUnicode=true&character_set_server=utf8mb4
My Entity column definition
#Column(name = "question", columnDefinition = "TEXT")
private String question;
I tried by doing
1.change in column definition to "nvarchar" i got hibernate error.
2.In mysql changed column definition to ALTER TABLE table CHANGE column column VARCHAR(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
referred, to change mysql tables definitions enter link description here
In case of any modification or mistake help me.
Change the character encoding to utf8_general_ci by,
ALTER TABLE test_tb MODIFY COLUMN col VARCHAR(255)
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
And then,
insert into test_tb values("₹");
Look at #Nationalized annotation, it may help your problem Annotation Type Nationalized
#Nationalized
#Column(name = "question", columnDefinition = "TEXT")
private String question;
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 am building a REST-Interface for some Application and I use JPA and Hibernate to access a SQL-Database.
Now I am trying to check if a given nickname already exists.
I am doing it this way:
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
CriteriaQuery<DBUser> query = builder.createQuery(DBUser.class);
Root<DBUser> from = query.from(DBUser.class);
Predicate uniqueNickname = builder.equal(from.get(DBUser_.nickName),newNickname);
query.select(from).where(uniqueNickname);
if (this.entityManager.createQuery(query).getResultList().size() == 0) {
//ok
} else {
//not ok
}
If I now have a User TEst in the database and newNickname="teST"
it puts the User TEst into the resultlist.
(I checked what the name in the resultlist is and it says TEst)
I am using the mysql connector "mysql-connector-java-6.0.6.jar".
Normally, CriteriaBuilder#equal is case-sensitive, you can achieve equals ignore case by comparing strings in uppercase variant:
Predicate uniqueNickname = builder.equal(builder.upper(from.<String>get(DBUser_.nickName)),
newNickname.toUpperCase());
In your case, the DB ignore the case sensitive completely.
Checking your MySQL DB and change the collation setting (the collation with _ci suffix is case-insensitve)
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.
Hi I have very big problem. I have a DetachedCriteria and I named it dc. I declared it this way DetachedCriteria dc = getDetachedCriteria(). I want to add a collation statement before the order by. The purpose of collation is to handle ñ. The statement I want to add is COLLATE utf8_spanish_ci. I did it this way dc.add(Restrictions.sqlRestriction(" COLLATE utf8_spanish_ci ")). Of course I got an error because this is wrong. I don't know to do it. Please help.
You can execute native SQL queries in order to take advantage of your particular database features, this is how is done in hibernate using detached criteria...
List<YourEntity> list = (List<YourEntity>) yourEntityDAO.getHibernateTemplate().execute(
new HibernateCallback() {
#Override
public Object doInHibernate(Session session) throws HibernateException {
SQLQuery sq = session.createSQLQuery("SELECT * FROM MY_TABLE");
return sq.addEntity(YourEntity.class).list();
}
});