Changing database location is simple – just launch dump on source database server, import it into destination database, redirect domain and voila! You can use this method to migrate your database into newer database engine version. But what can you do if you realize whole backend must be changed (i.e. from MySQL to PostgreSQL)?
Migrating SQL dump to different database dialect is not very easy (column types / dates formats as first examples come to mind). But you don’t have to operate on SQL dumps. The simple answer here is: “dumpdata”.
Second level cache in Hibernate allows to greatly speed-up your application by minimizing number of SQL queries issued and serving some results from in-memory cache (with optional disk storage or distributed cache). You have option to plug in different cache libraries (or to Bring Your Own Cache – an approach popular among my colleagues from India ). There are caching limits you must be aware of when implementing 2nd level cache.
I bet everyone knows how to enable SQL logging for Hibernate. If you add this parametr to Hibernate configuration:
you will see queries like this in log file:
select roles0_.EntityKey as Entity9_1_, roles0_.ENTITYKEY as ENTITY9_168_0_
from USERROLE roles0_
but wait: what value is passed as parameter by Hibernate? (parameters are marked as “?” in JDBC) You have configure TRACE level for some log categories, here’s example for simplelog.properties:
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of XYZ.setStatus().
Using primitive types (long) where NULL is possible or using wrong type (i.e. String if “char” is declared in HBM file).
Change from primitive type (long) to wrappers (Long) or ensure correct type is defined in mapping files.
I was getting the following error:
ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
<property name="customer" column="CustomerId" />
the fix for above error was to use many-to-many tag instead of plain <property>:
<many-to-one name="customer" column="CustomerId" />
Note that class is not required here – it’s computed from return type of getCustomer() getter by reflection.