views:

182

answers:

1

Hi all,

I am running a JBoss Seam web application with Hibernate as the persistence provider. I am considering migrating to OSGI to simplify deployment and updates.

I don't have any experience yet with OSGI, so I don't know if this can be done and what the limitations are.

For instance, if I change entity classes and I want Hibernate to drop some tables and create some new ones, will that be possible? Does hibernate need to have hooks into OSGI so it knows to drop table a and create table b?

Walter

A: 

I'm not sure I fully grasp your question. If you choose to use OSGi to modularize your application, that choice has no impact on the behavior of Hibernate. You can, of course, make calls into Hibernate's SchemaExport or SchemaUpdate APIs when you activate bundles to manage your schema, but Hibernate won't drive that process for you. You'll have to do it yourself.

Rob H
Ok, Rob, I think that makes sense. So every time I update my entity classes, I will have to call Schema Export / Update? I think all I will be doing is adding entity classes. If I update the table structure, it becomes much harder to automatically migrate data. I would need to export data, then re-insert it with the new schema.
Yes, Hibernate's SchemaUpdate tool is pretty simplistic. You'll want something more advanced if you need to do any kind of non-trivial schema conversion while preserving exisiting data. (My company built an in-house tool for this purpose.) At any rate, if you do call Hibernate's schema tools during bundle activation, remember to also create new Configuration and SessionFactory objects to pick up your changes.
Rob H