{"id":24799314,"url":"https://github.com/xgp/sql2java","last_synced_at":"2025-06-30T11:04:45.806Z","repository":{"id":4640574,"uuid":"5785472","full_name":"xgp/sql2java","owner":"xgp","description":"Fork of sql2java, a trusty, old code generator","archived":false,"fork":false,"pushed_at":"2017-02-01T09:34:56.000Z","size":121,"stargazers_count":16,"open_issues_count":0,"forks_count":7,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-30T11:04:43.919Z","etag":null,"topics":["java","orm","sql"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xgp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-12T20:26:19.000Z","updated_at":"2025-05-02T17:07:46.000Z","dependencies_parsed_at":"2022-09-16T16:00:27.812Z","dependency_job_id":null,"html_url":"https://github.com/xgp/sql2java","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xgp/sql2java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgp%2Fsql2java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgp%2Fsql2java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgp%2Fsql2java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgp%2Fsql2java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgp","download_url":"https://codeload.github.com/xgp/sql2java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgp%2Fsql2java/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262762459,"owners_count":23360329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","orm","sql"],"created_at":"2025-01-30T02:17:49.693Z","updated_at":"2025-06-30T11:04:45.778Z","avatar_url":"https://github.com/xgp.png","language":"Java","readme":"# sql2java #\n\nThis is a fork of an abandoned project on SourceForge by the same name \u003chttp://sql2java.sourceforge.net/\u003e. It is heavily modified from the original version. I started using this around 2005 as a quick \u0026 dirty way to generate Java beans and data access managers from a SQL database. I still use it, as I have found many ORM tools like Hibernate to be unweildy and more trouble than they're worth. \n\nThis differs from the original project in the following ways:\n- Build uses Maven. Packaged as a Maven plugin. sql2java-maven-plugin and sql2java-lib are in Maven Central.\n- New Maven plugin (sqlfile) for sourcing a SQL DDL before generation.\n- sql2java-lib runtime library is now a mandatory dependency.\n- No more web widgets or factories. Just beans and managers.\n- *Managers return Lists instead of arrays.\n- Manager class is gone. BaseManager now takes a DataSource directly.\n- Generates a (SchemaName)Database.java factory with get*Manager() methods for all managers. Intended as an easy entry point to extend as your application's DAO.\n- Management of transactions from the (SchemaName)Database.java class.\n- Uses generics to make the code more concise (and requires Java 1.5)\n- Not sure if anything but MySQL and HSQL support works anymore. PostgreSQL did work a while ago, but haven't checked in a bit.\n\nTo do in the future:\n- Add an interface for a cache providing a few convenience methods on top of a *Manager: T get(Id), List\u003cT\u003e get(List\u003cId\u003e), List\u003cT\u003e get(Key). Add optional runtime library with cache implementations. \n- The CodeWriter and Database classes are messy and fragile. Port to use SchemaCrawler \u003chttp://schemacrawler.sourceforge.net/\u003e. Also look at jOOQ \u003chttp://www.jooq.org/\u003e and see what they're doing.\n- Do something with foreign key mappings that is sane against bad definitions.\n- Do something better with compound primary keys (despite thinking they're a bad design decision).\n- Move the properties defined in the file into the Maven plugin definition. Allow a list of tables to be specified for generation.\n\n### Using the generator: ###\nEasiest way to try it out is to copy the structure in sql2java-test/.\n\nAdd the following to your POM file's build section:\n\n    \u003cbuild\u003e\n      \u003cplugins\u003e\n        \u003cplugin\u003e\n          \u003cgroupId\u003ecom.github.xgp\u003c/groupId\u003e\n          \u003cartifactId\u003esql2java-maven-plugin\u003c/artifactId\u003e\n          \u003cversion\u003e${sql2java.version}\u003c/version\u003e\n          \u003cexecutions\u003e\n            \u003cexecution\u003e\n              \u003cid\u003esql2java\u003c/id\u003e\n              \u003cgoals\u003e\n                \u003cgoal\u003esql2java\u003c/goal\u003e\n              \u003c/goals\u003e\n            \u003c/execution\u003e\n          \u003c/executions\u003e\n          \u003cconfiguration\u003e\n            \u003coutputDirectory\u003e${project.build.directory}/generated-sources/sql2java\u003c/outputDirectory\u003e\n            \u003cpropertiesFile\u003e${project.basedir}/src/main/resources/sql2java.properties\u003c/propertiesFile\u003e\n            \u003cdriver\u003eorg.hsqldb.jdbc.JDBCDriver\u003c/driver\u003e\n            \u003curl\u003ejdbc:hsqldb:file:${project.build.directory}/databases/test\u003c/url\u003e\n            \u003cuser\u003eSA\u003c/user\u003e\n            \u003cpassword\u003e\u003c/password\u003e\n            \u003cschema\u003ePUBLIC\u003c/schema\u003e\n            \u003cpackageName\u003ecom.test\u003c/packageName\u003e\n          \u003c/configuration\u003e\n          \u003cdependencies\u003e\n            \u003c!-- Add your JDBC driver here --\u003e\n            \u003cdependency\u003e\n              \u003cgroupId\u003eorg.hsqldb\u003c/groupId\u003e\n              \u003cartifactId\u003ehsqldb\u003c/artifactId\u003e\n              \u003cversion\u003e${hsqldb.version}\u003c/version\u003e\n            \u003c/dependency\u003e\n          \u003c/dependencies\u003e\n        \u003c/plugin\u003e\n      \u003c/plugins\u003e\n    \u003c/build\u003e\n\nAnd run:\n\n    mvn sql2java:sql2java compile\n\nThere is a log at target/velocity.log that will tell you if anything failed, and running Maven with the -e flag should be somewhat informative.\n\n### Using the generated code: ###\nGiven the schema example in sql2java-test/src/main/sql/00-test.sql:\n\n    // Create a Database from your DataSource\n\tPublicDatabase db = new PublicDatabase(ds);\n\n    // Transactionally create some rows\n\ttry {\n\t    db.beginTransaction(Txn.Isolation.REPEATABLE_READ);\n\t    Person s0 = db.createBean(Person.class);\n\t    s0.setUsername(\"hansolo\");\n\t    s0.setFirstName(\"Harrison\");\n\t    s0.setLastName(\"Ford\");\n\t    s0.setCreateDate(new Date());\n\t    s0 = db.save(s0);\n\t    Phone m0 = db.createBean(Phone.class);\n\t    m0.setPersonId(s0.getId());\n\t    m0.setPhoneType(1);\n\t    m0.setPhoneNumber(\"+14105551212\");\n\t    m0.setCreateDate(new Date());\n\t    m0 = db.save(m0);\n\t    db.commitTransaction();\n\t} finally {\n\t    db.endTransaction();\n\t}\n\n    // Find the rows\n\tPerson s1 = db.loadUniqueByWhere(Person.class, \"WHERE USERNAME='hansolo'\");\n\tPhone m1 = db.loadUniqueByWhere(Phone.class, \"WHERE PHONE_NUMBER='+14105551212'\");\n\n    // Delete the rows (auto-commit)\n\tdb.deleteByWhere(Phone.class, \"WHERE PHONE_NUMBER='+14105551212'\");\n\tdb.deleteByWhere(Person.class, \"WHERE USERNAME='hansolo'\");\n\n### Customizing: ###\nThe Velocity templates used by the code generator are in src/main/resources. If you add a new template, you must specify it in your properties file under mgrwriter.templates.perschema or mgrwriter.templates.pertable. \n\n### Dependencies: ###\nRuntime dependencies for the generated code are sql2java-lib, slf4j for logging, and whatever JDBC driver you need for your database.\n\n### Feedback: ###\nPlease submit a pull request if you'd like to see something changed. \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgp%2Fsql2java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgp%2Fsql2java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgp%2Fsql2java/lists"}