Java新手:JPA和EJB工作流程问题
我刚刚学习 JPA 和会话 bean。我已经完成了一个简单的数据库模型(使用 MySQL Workbench 设计的架构),并使用 IDE (NetBeans) 向导来生成 JPA 实体类和会话 Bean。
我的问题与数据模型更改时的适当工作流程有关。例如,如果我向表中添加一列,某些 IDE 是否具有更新实体类和会话 Bean 以反映新的基础数据结构的功能?或者这些更改最好手动处理?
我读过这个答案,但答案有点超出了我的经验迄今为止。
I'm just learning about JPA and session beans. I've worked through a simple database model (schema designed using MySQL Workbench) and used an IDE (NetBeans) wizard to generate the JPA entity classes and session beans.
My question has to do with an appropriate workflow when the data model changes. For example, if I add a column to a table, do some IDE's have features that will update entity classes and session beans to reflect the new underlying data structure? Or are these changes best handled manually?
I read this answer on SO, but the answer was a bit beyond my experience so far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的经验,这些生成的实体通常并不完美(例如,您获得 FK 的属性而不是关系)。因此,我将它们视为一个起点,但肯定不是最终结果。
我不知道有任何工具可以完美支持往返工程,特别是在使用自下而上的方法,即从数据库模式开始时(某些提供程序允许在使用自上而下的方法时,即从实体和映射开始时更新模式,但这也不完美)和IMO 最好手动处理更改。
实际上,我个人认为 JPA 代码生成工具(无论您使用自上而下还是自下而上的方法)主要是“引导”工具,它们有助于开始工作。但在某些时候,您必须开始手动同步内容(这是您链接到的问题中提到的迁移工具的有用之处)。
To my experience, these generated entities are often not perfect (e.g. you get attributes for FK instead of relations). I thus consider them as a starting point, but certainly not a final result.
I'm not aware of any tool supporting perfectly round-trip engineering, especially when using a bottom-up approach i.e. when starting from the database schema (some providers allow to update a schema when using a top-down approach i.e. when starting from the entities and mappings but this isn't perfect either) and changes are IMO best handled manually.
Actually, I personally consider JPA code generation tooling (whether you use a top-down or a bottom-up approach) mostly as "bootstrapping" tools, they help to get things started. But at some point, you'll have to start syncing things by hand (which is where migration tools like the one mentioned in the question you linked to are useful).