java pojo生成,如何动态创建Java POJO类?

博主探讨了从数据库表动态生成POJO类的需求,指出使用ORM框架如Hibernate或JPA可能是更好的选择,而非自行创建动态类。动态类的引用、管理以及重启后重建等问题可能导致复杂性和维护成本增加,建议重新考虑设计架构,因为动态数据模型在长期维护、优化和调试上可能存在困难。
摘要由CSDN通过智能技术生成

I have seen a post in this website regarding the dynamic POJO generation. I have the similar requirement now.

I have some tables in the database. I want to have a POJO class for each table with fields and corresponding getters and setters. These classes are to be created dynamically. Once these classes are created I should use those setters and getters in other class to get and set the data and return the Java object.

I have seen BCEL, CGLIB and some other open source tools for this, but couldnt find the proper example. Can you help me?

解决方案

Have you looked at any of the ORM (Object Relational Mapping) frameworks out there that have been created for just this purpose? Hibernate or the Java EE 6 standard JPA, for instance. It sounds like you are starting down on a path of re-inventing something that is both pretty complex and very time consuming - never a good idea.

UPDATE: in response to comment

Well, I can only say that you guys are building yourselves into a world of hurt. Consider:

If you rely on completely dynamic classes, you are you going to reference those classes and objects from other classes? Through reflection? And how are you going to keep track of all the created classes, their names and the names of their setters and getters?

What happens when you have to restart your system? How are you going to re-create all those dynamic classes?

With a completely dynamic database, how are you going to be able to do any performance optimization on it? Like indexing, for instance.

I can only strongly advise you to re-think your architecture. Dynamic datamodels are a mess to begin with, and next to impossible to maintain, optimize and debug. I've seen systems based on it and it's not pretty. IBM Lotus WCM is a prime example of data model horror. A properly designed and normalized relational model will be better in 99,99999999% of the cases.

Combining this with a harness of dynamic, run time ORM classes will be utterly impossible to maintain (and understand).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值