Given a sqlite database as input, I want to know how can i can generate an ORMLite java class that map with the associated database. Many thanks.
相关问题
- SQL/SQL-LITE - Counting records after filtering
- What SQLite NuGet package do I need
- How to write the array into the sqlite database fo
- Groupwise MAX() on a subquery
- metaData.getPrimaryKeys() returns a single row whe
I am new to ORMLite and also have the same need.
For SQLite, I read and parse the SQL statement in the field "sql" of table "sqlite_master".
Although it works well with tables, I had to find an other way to deal with views; now I use Excel to load data from views into ADO objects and parse fields' properties to generate Java POJO class definition text, then paste it onto IDE.
It's not perfect, saved me a lot of time though.
You could try Telosys Tools, an Eclipse plugin for code generation working from an existing database with customizable Velocity templates
See: https://sites.google.com/site/telosystools/
A set of templates is available on GitHub for JPA :
//github.com/telosys-tools-community/jpa-templates-TT206-v2
A Java class for JPA is very near to ORMLite so it's possible to adapt the templates in oder to generate ORMLite java classes
A global tutorial for Spring MVC and JPA :
//sites.google.com/site/telosystutorial/springmvc-jpa-springdatajpa (you can just consider the JPA bundle)
This is not something that ORMLite can do itself -- you are going to have to help it. If you want to edit your question and include your SQLite schema, I'll edit my answer to include some of the necessary object.
For example, here are some field mappings:
I would suggest creating a class and using the
TableUtils.getCreateTableStatements(ConnectionSource, Class<T>)
method to see what schema is dumped out and how it compares to your existing schema. Then add or modify the fields until you get as close a match as possible.