Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate Tips: Migration of Hibernate\MySQL to Hibernate\Azure SQL  RSS feed

 
Ginny Harvey
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thorben,

I am new to Hibernate, and have come across it through becoming a volunteer for a not-for-profit organisation providing healthcare to developing countries using digital technology. We are about to take delivery of a a software project written by students which has been written using Hibernate and a MySql database. As the project progresses we are intending to migrate to Azure SQL, to avoid costs we will incur using MySql in the cloud. My understanding is that Hibernate will facilitate an easy migration in this respect. Can you give any tips for problems that we are likely to encounter?

Any help would be very gratefully received.

Thank you!
 
Mohammed Sardar.
Ranch Hand
Posts: 126
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was one of my recent interview Question. An engineering company uses an accounting software which has been configured with SQL Server but soon after adopting Hibernate in their accounting software they planned to move Oracle. How hibernate handles this situation ? I answered by changing Dialect property of hibernate will manage. what should I answer ?  Any comments to learn please.Thanks.
 
Rob Spoor
Sheriff
Posts: 21019
84
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you're using RDBMS specific functions, or native queries, changing a dialect should be enough. You should test properly though - the translation from JPQL or criteria queries to native queries may lead to different results (e.g. if a query was first translated to an outer join, but now to an inner join - I've seen it happen...).
 
Mohammed Sardar.
Ranch Hand
Posts: 126
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPQL Java Persistence Query Language Right ?
 
Tim Holloway
Saloon Keeper
Posts: 18636
70
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohammed Sardar. wrote:JPQL Java Persistence Query Language Right ?


Correct. And Rob has nailed it. Avoid DBMS-specific constructs such as native queries, dependencies on vendor-specific data types (JPA will mitigate that sort of thing, but it cannot handle every possible case), and functions unique to a particular DBMS. Also, avoid stored procedures!!! They are among the least portable constructs, and most of what they do isn't even under direct control of JPA, so JPA cannot help much.

You can get bitten by subtle differences such as the granularity of imprecise data types (some DBMS's handle dates as date+time+milliseconds, others are precise only to seconds, or even days).

Do these things, and the task of transformation will be a lot easier. I have a system that does its db unit testing with Apache Derby, but runs in production under IBM's DB2 and there are no source code differences made to the app at all between the 2 DBMS's.

And incidentally, if you're careful, you can not only switch DBMS's, but JPA providers. Several years back I had a project that started out under Apache OpenJPA, ran into a problem, and I converted it to Hibernate JPA by making minor changes to a config file or two and replacing 3 Maven dependencies (swapping out the OpenJPA libraries for Hibernate).
 
Message for you sir! I think it is a tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!