简体   繁体   English

动态对象关系映射

[英]dynamic object relation mapping

I am trying to create an application in java which pulls out records from the database and maps it to objects. 我正在尝试用Java创建一个应用程序,该应用程序从数据库中提取记录并将其映射到对象。 It does that without knowing what the schema of the database looks like. 它不知道数据库的架构是什么样的。 All i want to do is fetch all rows from all tables and store them somewhere. 我要做的就是从所有表中获取所有行并将它们存储在某个地方。 There could be a thousand tables with thousands of records each. 可能有一千个表,每个表有数千个记录。 The application doesn't know the name of any table or attribute. 应用程序不知道任何表或属性的名称。 It should map "on the fly". 它应该“即时”映射。 I looked at hibernate but it doesnt give me what i want for this app. 我看着冬眠,但它没有给我我想要这个应用程序的东西。 I don't want to create hard-coded xml files and classes for mapping. 我不想创建用于映射的硬编码xml文件和类。 Any ideas how i can accomplish this ? 有什么想法我可以做到这一点吗? Thanks 谢谢

Oracle has a bunch of data dictionary views for metadata. Oracle有许多用于元数据的数据字典视图。

ALL_TABLES, ALL_TAB_COLUMNS would be first places to start. ALL_TABLES,ALL_TAB_COLUMNS将是第一个开始的地方。 Then you'd build ad-hoc queries based on what you get out of there. 然后,您将根据所获得的内容来构建即席查询。 Not sure whether you have to deal with all data types (dates, blobs, spatial, user-defined....). 不确定是否必须处理所有数据类型(日期,blob,空间,用户定义...)。

Not sure what you mean by "store them somewhere". 不知道“将它们存储在某处”是什么意思。 If you start thinking CSV or XML files, you'll need to escape various characters from VARCHAR2 columns. 如果您开始考虑CSV或XML文件,则需要从VARCHAR2列中转义各种字符。

If you are looking for some generic extract/unload routines, you should look at what is already available in the database or open-source/commercially. 如果您正在寻找一些通用的提取/卸载例程,则应该查看数据库中或开放源代码/商业可用的内容。

MyBatis provides a pretty simple way to map data results to objects and back, maybe check that out? MyBatis提供了一种非常简单的方法来将数据结果映射到对象并返回,也许可以检查一下?

http://code.google.com/p/mybatis/ http://code.google.com/p/mybatis/

不要翻转,但是对于此任务,您可能想要查看Ruby on Rails及其ActiveRecord方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM