0

I have a question about Hibernate.

I want to connect to a database and get informations about the tables (all its columns and its metadata - datatype, collation, index, description, key etc.) while runtime using java.

I have no access to this database while developing. The java application will be installed in other companies not knowing they're databases. Is it possible using Hibernate to achieve this goal?

I cannot create an mapping in xml or use annotations, because i do not know the schemas/tables/columns.

In other words perhaps: Is it possible to create xml mapping while application runtime? Create objects out of this xml files and read properties from the created objects while runtime?

I hope this question is clearer now.

1
  • Since ORMs usually map DB tables to a programming language classes what would be the advantage of using ORM in your case? How are you going to use these classes if they are unknown to you at compile time? Even if you plan to use reflection and display the classes and their properties to the user, won't they be named exactly like DB tables and columns (I guess the code will not generate user-friendly names)? Hibernate is not necessary for this. Commented Nov 20, 2012 at 10:52

4 Answers 4

7

Actually this is possible, though extremely difficult!

This post will get you started: http://www.manydesigns.com/en/blog/configuring-hibernate-programmatically-part-2

Sign up to request clarification or add additional context in comments.

Comments

1

Why do you want to do this with Hibernate? This seems more like a job for regular JDBC. If what you say is true and all you want to do is obtain database metadata.

http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSetMetaData.html

1 Comment

Thx for this answer, but i want to scna different DB's and write a one schema into it. So i tought the easiest way would be to operate on an ORM Mapper. Retireving the metadata from the ORM an use it so store meta + additional data into a own created schema. In this way i do not hav to write diffrent DBWriterClasses for MySQl/Oracel/MsSql etc.. stackoverflow.com/questions/10371536/…
0

No its not possible in Hibernate.

Using Hibernate its mandatory to map your class file to Database Tables. And without having any knowledge about database schema, its impossible to get such details.

Comments

0

No.Its not possible using Hibernate

1 Comment

It is, see my link above, the folks at manydesigns have done it. Plus, their code is there for all to see. I've used it to help me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.