lundi 13 juillet 2015

Java Persist without Entity

I am working on an JavaEE application, and there are almost 1000+ tables in the database, now I have to query the records by the parametes from the client.

Generally I will create one Entity for each table, and create the Dao,Service to do the query.

However I meet two problems:

1 Number of the tables

As I said, 1000+ table with almost 40+ columns for each, it would a nightmare to create the entity one by one.

2 Scheme update

Even I can create the Entity by program, the schema of the data may change sometime which is out of my control.

And in my application, only read operations are related to these kinds of data,no update,delete,create required.

So I wonder if the following solution is possible:

1 Use Map instead of POJOs

Do not create POJOs at all, use the native Map to wrap the columns and values.

2 Row mapping

When querying using Hibernate or Spring JdbcTemplate or something else, use a mapper to map each row to an entry in the map.

If yes, I would use the ResultMetaData to detect the column name,type,value:

ResultMetaData rmd=rs.getMetaData();

for(int i=0;i<rmd.getColumnCount();i++){
    Type t=rmd.getType(i)
    if(t==....){
        ...
    }else if(t=...){
        ...
    }
}

Looks like part of JPA's job, any library can used here?

If not, any other alternatives?

Aucun commentaire:

Enregistrer un commentaire