Abhishek
Abhishek

Reputation: 2175

Java Class to Database Table Structure

I have some java classes like,

Class User {
    String email;
    String name;
    String password;
}

Class Point {
    int pointForA;
    int pointForB;
}

Is there any way to get database table structure(or SQL queries) from these java classes directly? I just want to avoid manual tables' creation in database. Thanks in advance.

Upvotes: 4

Views: 5804

Answers (1)

Anil Sharma
Anil Sharma

Reputation: 558

you can use jpa(Java persistence API). JPA can help you in directly creating tables from java classes. for DDL statements(i.e. creating tables) you need to have this line in your persistence.xml file.

property name="eclipselink.ddl-generation" value="create-tables" (for eclipselink jpa provider )

this line will ensure that if your tables are not present in database then it will be created by java program

if you don't know about jpa then you need to read java ee tutorial like this

http://docs.oracle.com/javaee/6/tutorial/doc/bnbqa.html

Upvotes: 2

Related Questions