OSGi + 休眠
数据库操作不是分散在四个 (osgi) 包中,而是全部执行略有不同的操作。 我想创建一个(简单的)OSGi 包来负责所有持久性问题。 我觉得这并不像听起来那么简单,因为“每个包都有唯一的类加载器”。 所以我真正感激的是如果有人知道此类问题的解决方案。
Instead of having database actions scattered in four (osgi) bundles, all doing there slightly different things. I want to create a (simple) OSGi bundle that is responsible for all persistance issues. I feel that this is not as simple as it sounds because of the "unique classloader per bundle" thing.
So what I really would appreciate is if someone knows the solution(s) to this kind of problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我可以想到两种方法来解决类加载问题。
There are two ways I can think of to solve the classloading-issue.
(如果您使用 Hibernate Annotations)
当 Hibernate 捆绑包获悉带注释的类时,保存所有实体类加载器。
然后在构建 SessionFactory 之前执行类似的操作。
(If you are using Hibernate Annotations)
Save all the Entities class loaders when the Hibernate bundle is informed about an annotated class.
Then do something like this before building your SessionFactory.
刚刚在 Bundle 类/api 中发现了一个有趣的方法。
这必须解决一些类加载器问题吗?
Just found an interesting method in the Bundle class/api.
This must solve some class loader issues?
我建议远离伙伴类加载,因为它特定于 Eclipse 的 Equinox 实现,在我看来,人们让它工作,但他们不明白为什么,每个人最终都会成为其他人的伙伴。 这会阻止您正确理解 OSGi 类加载的工作原理以及使用它所需使用的模式(复合类加载器、上下文类加载、OSGi 服务……)。
如果您的持久性捆绑包提前知道需要持久保存什么类型,那么该捆绑包可以导入包含您的域类的所有必需包(Require-Bundle 是邪恶的)。
管理上下文类加载器(如 Roger 的回复)可以帮助 Hibernate,尽管我建议使用 Spring dm 之类的东西将其隐藏在 OSGi 服务后面。
I'm going to recommend to stay away from buddy class loading as it's specific to Eclipse's Equinox implementation and, in my opinion, people get it to work but they don't understand why and everyone ends up as a buddy of everyone else. This stops you gaining a proper understanding of how OSGi classloading works and the patterns you need to use (composite class loaders, context class loading, OSGi services, ...) to work with it.
If your persistence bundle knows ahead-of-time what types it needs to persist, then the bundle can import all required packages (Require-Bundle is evil) that contain your domain classes.
Managing the context class loader (as in Roger's reply) can help with Hibernate, though I'd suggest using something like Spring dm to hide that behind an OSGi service.
Hibernate 确实支持 OSGi 但它是一个 持续努力。
Hibernate does support OSGi but it's an ongoing effort.