disasterkid
disasterkid

Reputation: 7278

Generate model classes from the database

I have created a Spring Boot project and would like to communicate with an SQL Server 2017 database running on a Docker Container.

What is the quickest way to generate code for model classes in Eclipse (Oxygen.2 Release 4.7.2)?

I put my pom.xml and application.properties here if it helps.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.blahblahblah</groupId>
    <artifactId>querytofile</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>querytofile</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

application.properties

spring.datasource.url=jdbc:sqlserver://localhost;databaseName=myDB
spring.datasource.username=sa
spring.datasource.password=BLAHBLAHBLAH
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto = create-drop

Update: Snapshot from Marketplace

enter image description here

Upvotes: 2

Views: 5866

Answers (1)

Neeraj Benjwal
Neeraj Benjwal

Reputation: 1351

open eclipse IDE :

Go to > help > eclipse marketplace > search JPA > select g9 Database Import as below.

plugin

restart eclipse IDE.

Right click on project > import > search for Import Database Model as below.

Import DB

provide required fields and generate the entities.

Upvotes: 1

Related Questions