Say if we have an object model designed with 500+ classes which we want to persist to a relational database using hibernate, is there any standard way to do this? It might be easier to map each class to a separate table but from the database point of view I assume this would be a big performance hit. So the best way would be to map these class to relational tables. But to do this do we have to design the database first and then do the mapping or can we generate the database structure through OR-mapping tools?
All the examples I see are only two or three classes and the mapping could be customized manually by editing the hbm.xml files, but I wonder how to do this mapping in a large scale. Could someone elighten me with some existing tools that could generating this mapping? ofcourse with some examples would be good.
Not sure if I mentioned my question clear, I just have a bunch of persistable classes and dont have a relational database designed or hbm.xml mapping files written. I would like to know if there is a way/tool to generate the mapping files and the database from the persistable classes. And also would like to know the right way to do this, ie, do we need to design the relational database first and do the mapping?
I had looked through the SchemaUdate and SchemaExport functions, but those seem to require hbm.xml files written. I just have the object model and want to generate hbm.xml files as well as the database schema.
Annotations...hmmm.... i spent some time trying to see what Annotations are and how it is useful. It seems to be sleek and get rids of mapping xml files but its kind of scary when they ask to use EJB3 persistence (what happened to the POJO's with no dependencies?). At least I dont think it requires a EJB container and can run with just a servlet container like Tomcat (correct me if i am wrong?). Also read somewhere that Annotations will negate the use of xdoclet! so better go with Annotations instead of trying to learn xdoclet. So has anyone played with Annotations and have comments on how better it is compared to xml mapping files or xdoclet? Being a newbie to Hibernate, I am still not able to make a decision on whether to design the database and object model separately and do the mapping later (in which case i can just start with xml mapping) or should I do a bottom down approach to generate the mapping and database design from object model. Would be great if someone could clear this for me!
Hey. It is really hard to put here an answer that will suite everybody. First you have to ask yourself whether your application will/should be available only for JDK 5.0 and will be running in EJB container. If your answer to both is yes then you might start considering use of Hibernate Annotations.
Yes with annotations there is no need of *.hbm.xml files and xdoclet2(note that xdoclet1 does not support Hibernate 3). The better thing for annotations is that they are compile safe, in the contrary when writing your mapping files(or generating them using xdoclet).Single typo in your mapping file can cost you valued time figuring out that is a problem.
There is one more very important thing for you guys. Currently Hibernate Annotation Configuration can be instantiated only programatically, that means you are now still not able to define it in the hibernate.cfg.xml.
Hopefully this helps.
SCJP 1.5 (done, at last)<br /> <br />"If everything seems to be going well you have obviously overlooked something."
She'll be back. I'm just gonna wait here. With this tiny ad: