{"id":29538717,"url":"https://github.com/mmaunze/sqltojpa","last_synced_at":"2026-05-08T00:33:33.863Z","repository":{"id":304743296,"uuid":"1019795707","full_name":"mmaunze/sqlToJPA","owner":"mmaunze","description":"sqlToJPA is a tool for automatically generating Java JPA (Java Persistence API) entity classes from SQL schema files. It parses CREATE TABLE statements, maps SQL data types to Java types, and creates fully annotated Java classes with fields, getters, setters, constructors, relationships, and equals/hashCode methods.","archived":false,"fork":false,"pushed_at":"2025-07-14T23:32:06.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-15T03:19:03.816Z","etag":null,"topics":["cpp","java","jpa-entities","orm","python","sql"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmaunze.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-14T22:18:34.000Z","updated_at":"2025-07-14T23:32:10.000Z","dependencies_parsed_at":"2025-07-15T03:27:45.737Z","dependency_job_id":"e17250ac-32a4-4b51-9b1f-f0a3cecab760","html_url":"https://github.com/mmaunze/sqlToJPA","commit_stats":null,"previous_names":["mmaunze/sqltojpa"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mmaunze/sqlToJPA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaunze%2FsqlToJPA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaunze%2FsqlToJPA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaunze%2FsqlToJPA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaunze%2FsqlToJPA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmaunze","download_url":"https://codeload.github.com/mmaunze/sqlToJPA/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmaunze%2FsqlToJPA/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265567401,"owners_count":23789472,"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":["cpp","java","jpa-entities","orm","python","sql"],"created_at":"2025-07-17T05:15:22.997Z","updated_at":"2026-05-08T00:33:33.824Z","avatar_url":"https://github.com/mmaunze.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqlToJPA\n\n`sqlToJPA` is a tool for automatically generating Java JPA (Java Persistence API) entity classes from SQL schema files. It parses `CREATE TABLE` statements, maps SQL data types to Java types, and creates fully annotated Java classes with fields, getters, setters, constructors, relationships, and `equals`/`hashCode` methods. The project includes three implementations:\n\n- **sqlToJPAPython**: A Python-based implementation (`sqlToJPAPython/` directory).\n- **sqlToJPAJava**: A Java-based implementation (`sqlToJPAJava/` directory).\n- **sqlToJPAcpp**: A C++-based implementation (`sqlToJPAcpp/` directory).\n\nAll implementations produce identical Java JPA entity classes, offering flexibility to use Python, Java, or C++ depending on your environment or preference.\n\n## Features\n- Converts SQL data types to appropriate Java types (e.g., `BIGINT` to `Long`, `VARCHAR` to `String`, `TIMESTAMP` to `LocalDateTime`).\n- Supports primary keys (`@Id`, `@GeneratedValue`), foreign keys (`@ManyToOne`), and constraints like `NOT NULL`.\n- Handles `AUTO_INCREMENT` and default values in the generated entities.\n- Generates each entity in a separate `.java` file under the specified package and output directory.\n- Includes proper JPA annotations (`@Entity`, `@Table`, `@Column`, `@JoinColumn`, etc.).\n- Supports relationships between tables based on foreign key constraints.\n\n## Workflow Diagram\nThe following Mermaid diagram illustrates the workflow of the `sqlToJPA` tool, showing how each implementation processes an SQL schema file to produce Java JPA entity classes:\n\n```mermaid\ngraph LR\n    A[SQL Schema File\u003cbr/\u003eschema.sql] --\u003e|Lê o SQL de| B(sqlToJPA\u003cbr/\u003eJava Application)\n    B --\u003e|Gera Entidades JPA| C[Java JPA Entities\u003cbr/\u003ee.g., Customer.java, Product.java]\n    C --\u003e|Salva em| D[Diretório de Pacote\u003cbr/\u003ee.g., src/main/java/com/example/entities]\n```\n\n## Requirements\n### For sqlToJPAPython\n- Python 3.6 or higher (uses `pathlib`, `dataclasses`, and type hints).\n- No external Python dependencies required.\n- Generated Java classes require Java 8 or higher (due to `java.time` classes like `LocalDateTime`) and JPA (`javax.persistence`) for compilation.\n\n### For sqlToJPAJava\n- Java 8 or higher (uses `java.time` classes like `LocalDateTime`).\n- No external dependencies beyond the standard Java library and JPA (`javax.persistence`).\n\n### For sqlToJPAcpp\n- C++17 or higher (uses `\u003cfilesystem\u003e` and other C++17 features).\n- A C++ compiler supporting C++17 (e.g., g++ 7.0 or later).\n- No external C++ dependencies required.\n- Generated Java classes require Java 8 or higher and JPA (`javax.persistence`) for compilation.\n\n### General\n- A SQL schema file containing `CREATE TABLE` statements.\n\n## Installation\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/mmaunze/sqlToJPA.git\n   cd sqlToJPA\n   ```\n2. Ensure you have the required tools installed:\n   - Python 3.6+ for `sqlToJPAPython`.\n   - JDK 8+ for `sqlToJPAJava`.\n   - C++17-compliant compiler (e.g., g++) for `sqlToJPAcpp`.\n3. Place your SQL schema file (e.g., `schema.sql`) in the project directory or a subdirectory.\n\n## Usage\nThe tool can be run using any of the three implementations (Python, Java, or C++). All produce identical Java JPA entity classes.\n\n### Using sqlToJPAPython\n1. Navigate to the Python implementation directory:\n   ```bash\n   cd sqlToJPAPython\n   ```\n2. Run the generator:\n   ```bash\n   python sql_parser_jpa_generator.py schema.sql com.example.entities ./generated-classes\n   ```\n   - `schema.sql`: Path to the input SQL schema file.\n   - `com.example.entities`: Package name for the generated Java classes (optional, defaults to `com.example.entities`).\n   - `./generated-classes`: Output directory for the generated files (optional, defaults to `./generated-entities`).\n\n### Using sqlToJPAJava\n1. Navigate to the Java implementation directory:\n   ```bash\n   cd sqlToJPAJava\n   ```\n2. Compile the Java source file:\n   ```bash\n   javac SQLParserJPAGenerator.java\n   ```\n3. Run the generator:\n   ```bash\n   java SQLParserJPAGenerator schema.sql com.example.entities ./generated-classes\n   ```\n   - Parameters are the same as for the Python version.\n\n### Using sqlToJPAcpp\n1. Navigate to the C++ implementation directory:\n   ```bash\n   cd sqlToJPAcpp\n   ```\n2. Compile the C++ source file:\n   ```bash\n   g++ -std=c++17 sql_parser_jpa_generator.cpp -o sql_parser_jpa_generator\n   ```\n3. Run the generator:\n   ```bash\n   ./sql_parser_jpa_generator schema.sql com.example.entities ./generated-classes\n   ```\n   - Parameters are the same as for the Python and Java versions.\n\n### Output\nAll implementations create a directory structure matching the package name (e.g., `./generated-classes/com/example/entities`) and generate one `.java` file per table.\n\n## Example SQL Schema\nCreate a file named `schema.sql` with the following content to test any implementation:\n```sql\nCREATE TABLE users (\n    id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,\n    username VARCHAR(50) NOT NULL,\n    email VARCHAR(100) NOT NULL,\n    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n    role_id INT,\n    FOREIGN KEY (role_id) REFERENCES roles(id)\n);\n\nCREATE TABLE roles (\n    id INT PRIMARY KEY AUTO_INCREMENT,\n    name VARCHAR(50) NOT NULL\n);\n```\n\nRun any implementation, e.g., for C++:\n```bash\ncd sqlToJPAcpp\ng++ -std=c++17 sql_parser_jpa_generator.cpp -o sql_parser_jpa_generator\n./sql_parser_jpa_generator ../schema.sql com.example.entities ../generated-classes\n```\n\nOr for Python:\n```bash\ncd sqlToJPAPython\npython sql_parser_jpa_generator.py ../schema.sql com.example.entities ../generated-classes\n```\n\nOr for Java:\n```bash\ncd sqlToJPAJava\njavac SQLParserJPAGenerator.java\njava SQLParserJPAGenerator ../schema.sql com.example.entities ../generated-classes\n```\n\nThis will generate two files:\n- `./generated-classes/com/example/entities/Roles.java`\n- `./generated-classes/com/example/entities/Users.java`\n\n### Generated Output\n- `Roles.java`: Contains an entity with `Integer id` and `String name`, with proper `@Id`, `@GeneratedValue`, and `nullable = false` annotations.\n- `Users.java`: Contains an entity with `Long id`, `String username`, `String email`, `LocalDateTime createdAt`, `Integer roleId`, and a `@ManyToOne` relationship to `Roles`.\n\n## Output Example\n### Roles.java\n```java\npackage com.example.entities;\n\nimport java.io.Serializable;\nimport javax.persistence.*;\n\n@Entity\n@Table(name = \"roles\")\npublic class Roles implements Serializable {\n    // ... (fields, getters, setters, etc.)\n}\n```\n\n### Users.java\n```java\npackage com.example.entities;\n\nimport java.io.Serializable;\nimport java.time.LocalDateTime;\nimport javax.persistence.*;\n\n@Entity\n@Table(name = \"users\")\npublic class Users implements Serializable {\n    // ... (fields, relationships, getters, setters, etc.)\n}\n```\n\n## Notes\n- The tool assumes standard SQL syntax for `CREATE TABLE` statements. Complex schemas with non-standard syntax may require adjustments.\n- Foreign key relationships are mapped as `@ManyToOne`. Support for other relationship types (e.g., `@OneToMany`) may be added in future versions.\n- If a column definition cannot be parsed, a warning is logged to the console, and the column is skipped.\n- The output directory and package structure are created automatically if they don't exist.\n- The generated Java classes require a Java environment with JPA to compile and run.\n\n## Contributing\nContributions are welcome! Feel free to submit issues or pull requests to improve any implementation, such as adding support for more SQL types, relationship types, or annotations like Lombok or JPA validation. Please specify whether your contribution targets `sqlToJPAPython`, `sqlToJPAJava`, `sqlToJPAcpp`, or multiple implementations.\n\n## License\nThis project is licensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmaunze%2Fsqltojpa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmaunze%2Fsqltojpa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmaunze%2Fsqltojpa/lists"}