how to generate a java class code from a sqlite database for ORMLite

做~自己de王妃 提交于 2020-01-03 14:19:46

问题


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.



来源:https://stackoverflow.com/questions/5620272/how-to-generate-a-java-class-code-from-a-sqlite-database-for-ormlite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!