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.
问题:
回答1:
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)
回答2:
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.
回答3:
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:
- INTEGER -> int
- VARCHAR -> String
- BOOLEAN -> boolean
- TIMESTAMP -> Date
- BIGINT -> long ...
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.