Reputation: 1385
We are thinking about switching from our custom made code to an ORM, in order to simplify our code base and move to a possibly more robust code. Currently we have a few "system" tables and a variable number of "custom" tables. Those custom tables are different for each installation: a customer may have tables about invoices, anther may have tables about insurance policies, and so on. These custom tables may be added any time and should be immediately available to the users. We wrote a bunch of java classes following the DBO schema: a class for each system table, plus one generic class for the custom tables. And, we have a generic java object that instantiate the custom records; this class have generic methods like Object getProperty(String name)
.
We had a look at a few ORMs, but we could not find any that will simplify the use of such custom tables.
Is there anyone with similar experience? Thanks.
Upvotes: 6
Views: 2926
Reputation: 5518
You might want to look into ActiveJDBC. It follows dynamic mapping of model attributes to table columns. Check out the docs here http://javalite.io/setters_and_getters and here http://javalite.io/runtime_discovery.
Upvotes: 0
Reputation: 8552
Maybe it is a task for a query mapper framework better than an ORM.
For example, using MyBatis you can dynamically map even the table name (See Setting the FROM clause via parameter in MyBatis)
<select id="getLookupRows" parameterType="map" resultMap="lookupMap">
select id, name, active, valid
from ${table}
</select>
Upvotes: 1
Reputation: 1037
With orm, you should really focus on having a complete and mature object model. Having that done, mapping the objects to the relational database follows naturally. As the comment by '@JB Nizet' says, you need to have all your objects. So, perhaps it might be useful to reconsider your design and adapt it to work with an orm, be it hibernate or any other.
hibernate has an experimental feature called 'Dynamic models', I don't know a great deal about it, since I haven't had the chance to use it, but I guess it might give you some insights. Also note that it is an experimental feature at the moment and hence, might change in the future.
Upvotes: 0