Using Hibernate to work with text files

I use Hibernate in a Java application to access my database and works well with MS-SQL and MySQL. But some of the data that I have to show in some forms should come from text files, and in text files I mean files with human readability, they can be CSV, tab delimited delimiters, or even a pair of keys, values ​​in each line, because my data is as simple as that, but I prefer, of course, XML files.

My question is: can I use hibernation to read these files using HQL, Query, EntityManager and all these resources. Hibernate gives me file access. What file format should I use and how to set up My persistence.xml file to recognize files in the form of tables?

+6
java database hibernate text-files
source share
3 answers

Hibernate is written against the JDBC API. Thus, you need a JDBC driver that works with the file format you are interested in. Obviously, even for read-only access, this will not work well, but may be useful if it is not a high priority. On Windows, you can configure ODBC data sources for delimited text files, Excel files, etc. You can then configure JdbcOdbcDriver in your Java application to use this data source.

For most of the applications I'm working on, I would not consider this approach; I would use the import / export mechanism to convert from a real database (even if it is a database in progress, such as Berkeley DB or Derby) to text files. Yes, this is an additional step, but it can be automated, and performance is unlikely to be much worse than trying to directly use text files (it will probably be much better in general), and it will be more reliable and easy to develop.

+7
source share

Quick google came up

I hope this can be a source of inspiration?

+5
source share

As Erickson said, your only hope is to find a JDBC driver for this task. Maybe, xlsql (CSV, XML driver and Excel), which may be appropriate for the task. After that, you just need to find or write the simplest Hibernate dialogs that suits your driver.

0
source share

All Articles