ok I have spent more than 2 days now searching for tutorials and guide on creating a hibernate project, but I cant get things to work,
so I have Two Main questions
Are my Assumptions on how to use the hibernate framework correct?
If yes how do I proceed with each step?
Here are my Assumptions
1a. I complete data modeling step and have a schema ready to be used in application. (Done)
1b. I, then, create object relational mapping, meaning create physical classes to be mapped with each relation. (I have created these classes using NetBeans: New->Entity Classes from database. Will this work or I need to use hibernate somehow to create these?)
1c. I need to have hibernate jars in my application's classpath and some configuration/setting files
1d. I load these configuration/setting files
1e. Start using hibernate
Now all the tutorials I have seen don't elaborate on the details on how to do these steps, I have a lot of tables I cant create all classes manually. Can anyone give a concise solution to this? Something like:
for 1b create object classes using this command: hibernate-object.jar -db -classes
1c to create settings/configuration file use so and so command/plugin
1d this is how you load these files in code
There are several ways to start using hibernate, and your way (create database tables and relationships first) is one possible way.
My preference would be to create your Java Classes with annotations first, and have Hibernate set up the database tables for you.
A third possibility is to create the object relation mapping XML, and have Hibernate generate the Java classes AND database tables for you (middle-out).
Whichever way you choose, a useful starting point is to create a
HibernateUtilclass, as follows:That makes it easy to grab a
SessionFactorywhere needed. This approach is only to get you started and not recommended for production use as it's not very scalable, I'd consider Spring integration.