Reputation: 2452
My question is a bit tricky, I am trying best to make you understand what my requirement is.
Question: I want to generate a csv file from the database table ! see how.
a dummy method just for understanding.
public void convertToCsv(tablename , csv_file_path_name);
Scenario: When the table name is provided at runtime, the method requires to generate it's csv file, (table name can be any of the available tables in the database.), And for the accomplishment of this task, the class needs to generate dynamically POJO and hibernate mapping, because we can not define ourself the POJO's (Object Model) and hibernate mapping due to different coloumns in different tables.
tablename is provided at run time, so the method needs to generate POJO and hibernate mapping at run time.
Upvotes: 0
Views: 939
Reputation: 691835
This is impossible. Hibernate needs a well-defined set of entity classes with their mapping at startup. But really, if you're working at the table-level and just need all the columns of a table in a CSV file, Hibernate is not the right tool. You should just use JDBC.
Select everything from the table, get the result set metadata to know the number type and name of the columns, iterate over the JDBC result set, and generate a new CSV line for every row of the result set.
Upvotes: 1