为什么我必须重新定义数据结构两次?我应该吗?
仔细选择数据类型,最终创建一个复杂的类, 然后使用 HashMap,将那些第一个 Class 对象与键进行映射。 现在我可以创建数千个并访问它们,添加,删除等。
现在如果我想将它们存储在数据库中..
那么我从头开始?必须创建表吗?再次关心数据类型吗? 为了使我的对象适合数据库内,此外,我必须创建很多函数来“转换”数据..然后使用 SQL 进行查询..两种语言,第一个用于处理,第二个用于访问数据..用这些东西我记住实际的语言可能是未来的打孔卡..(当然,如果我想要一个网络界面,我可能不得不考虑第三种语言)
我认为使用java persistense,但这不是一个DB..
你在外面这样做两次吗?欢迎任何建议!
编辑:
Choosing carefuly datatypes, finally a complex Class is created,
then using a HashMap, those first Class objects get mapped with a key.
and now I can create thousands and access them, add, delete, etc..
Now if I want to store them in a DB..
So I start from scratch? have to create the table?, again take care about datatypes?
to make fit my objects inside the DB, furthermore I have to make a lot of function to "transform" data.. then SQL to make the queries..two languages, first to process, second to access data.. with this things I remember actual languages could be the punched cards of future ones.. (of course if I want a web interface I could have to think in a third one)
I think to use java persistense, but that's not a DB..
Are you doing this twice out there? any advices are welcome!
EDIT:
I have seen there are some tools as XStream or Simple to pass objects to XML (and vice versa), but well, of course XML is not a DB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这正是对象关系映射的用途。它(通常)允许您仅定义 Java 类或仅定义 DB 模式,并从另一个生成一个,并使“转换”或多或少自动发生。
对于 Java,Java Persistence API 和 Hibernate 是最常见的 OR 映射工具。
This is exactly what object-relational mapping is for. It (usually) allows you to define only the Java classes, or only the DB schema, and generate one from the other, and have the "transformation" happen more or less automatically.
For Java, the Java Persistence API and Hibernate are the most common OR mapping tools.
如果你想将数据库行映射到java对象,那么我使用了一个很好的程序,它需要0配置,只需创建一个具有类似字段的POJO(你必须在某个地方定义它),然后你就完成了。
http://www.easierjava.com/
If you are wanting to map database rows to java objects, then there is a nice program I use that takes 0 configuration, just create a POJO with similar fields (you have to define it somewhere), and your done.
http://www.easierjava.com/