My current application was built up in SQL Server 2008
server in JAVA
with Hibernate
and I had used HierarchyId
data type for department hierarchy in my database.
I had written SQL queries to deal with HierarchyId datatype. And I also have n-Level
of department tree structure.
Now I want to change my Database server from SQL Server 2008
to MySQL
as per business requirement.
After feasibility checking I came with the solution that my whole application will migrate to MySQL database server except HierarchyId
data type.
So my main challenge is to find alternate solution of HierarchyId
data type with the minimal change in coding.
What is the best way to implement department hierarchy in my database?
Thanks...
I faced the similar situation when our team decided to migrate from MS-SQL to MySQL. We resolved the issue using the following steps:
Thus we got rid of the hierarchyid functionality in MySQL.
Whenever we face such an issue, we just need to ask ourselves, what would we have done if this functionality would not have been provided by the tool we use. We generally end up getting the answer optimally.
Mysql has no equivalent that I'm aware of, but you could store the same data in a varchar.
For operations involving the HierarchyId, you're probably going to have to implement them yourself, probably as either user defined functions or stored procedures.
What sqlserver does looks like the "materialized path" method of storing a hierarchy. One example of that in mysql can be seen at http://www.cloudconnected.fr/2009/05/26/trees-in-sql-an-approach-based-on-materialized-paths-and-normalization-for-mysql/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With