Normally, hibernate uses POJO classes and JPA to manage entities. This works fine if you're working with a database with a known table name with known columns. In my case, I have both known and unknown tables in my database. In a known table, there are rows which have the names of unknown tables where I can find specific data pertaining to the detail for that row.
I know that there is one foreign key pertaining to the id of the parent row and I know the name of that column. I also know that there is a 2nd column, which combined with the foreign key, makes a unique identifier for that row.
In other words, suppose I have table PARENT with the following data:
Id Table name ...
1 CHILD1
2 CHILD2
3 CHILD1
...
Then there would be tables CHILD1 and CHILD2 (that I couldn't assume to exist prior to reading table PARENT) as follows:
ParentId RowId Column1 Column2 Column3 ...
1 1 ... ... ...
1 2 ... ... ...
3 1 ... ... ...
Notice that while I know about the existence of columns ParentId and RowId, I have no idea about the names of Column1, Column2, Column3. Similarly, if I were to show you CHILD2 table, there would be a ParentId and a RowId, but I couldn't tell you the names of the other columns.
I saw that Hibernate can deal with such things and they call them Dynamic Models. They can be set and accessed as Maps with key and value. However, although you can access data with a name, all the documentation requires that the column names are defined in the hbm.xml file. This implies that I have to define Column1, Column2, Column3, and I simply cannot know prior to runtime. It seems intuitive to me that with a Map, you could load all data under key/values where all the keys would be represented by the columns of that particular table so that you could simply cycle through all keys, but Hibernate doesn't seem to support it.
I happened to see this question, and while similar to my situation, unlike the OP of that question, I do not know the names of the columns in this table.
I'm using hibernate 4.2 which is recent. Does anyone know if such a thing is possible or if there is perhaps another way of doing it (preferably without having to change the database)? Many thanks!