0

I just want to know is there any way to write sql query that will work in all data base like i need not to change my Sql query if i am switching from Oracle to My sql Or some other databae,

Hibernate will help in this situation and if it will help how? I dont know any thing about hibernate please explain me how it will help .

Thanks Sudarshan

0

3 Answers 3

1

Hibernate uses object relation mapping.So u don't need to change your code or query uses hibernate.only you need to define only table relation in relation mapping xml and entity only.

But it wont work in all places. If you have complex relation query means you can write in the sepearte xml and you can read the query from the xml. But when you switch the database you need modify xml query based on the Sql syntax you don't need to change your code.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for your quick replay.I will go through that and implement hibernate in my project .One more thing if i want to change the database only thing that i want to modify is that the xml file?
Sorry for the delayed replay. When you switch the DB you need to change the DB configuration only. And one more thing you need modify query xml based on the DB switch. if you satisfied with the answer means kindly accept the answer.
Then kindly accept the answer. Click the tick symbol to accept..TnQ
I dont find any click symbol.
click on the check mark beside the answer to toggle it from hollow to green.
|
0

Hibernate create and Object Relational Mapping. That is it considers tables as objects. So we use HQL to query the objects and not on the database. Hibernate takes care of all that.

One another option is to have you queries in a external file. So that depending on the database you can switch the files and no code changes are required. This is not a widely accepted solution

Comments

0

ORM is your solution, It will make a separate layer over Database. And that layer will interact with your database. If you want to change the database from Oracle to MySql, just change the XML file and you are done.

Just try this tutorial: Definitely will help you alot: http://www.youtube.com/watch?v=GINvxAaXDbY

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.