Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 263737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:37:37+00:00 2026-05-11T22:37:37+00:00

I look for a way how I can create a ddl for my jpa

  • 0

I look for a way how I can create a ddl for my jpa annotated entities.
I prefer a pure java way for this.

If possible it would be nice to have generate the drop statements too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:37:37+00:00Added an answer on May 11, 2026 at 10:37 pm

    Export data from a database as sql

    Use the liquibase opensource project

    LiquiBase is an open source (LGPL), database-independent library for tracking, managing and applying database changes. It is built on a simple premise: All database changes (structure and data) are stored in an XML-based descriptive manner and checked into source control.

    Generate create and drop script for given JPA entities

    We use this code to generate the drop and create statements:
    Just construct this class with all entity classes and call create/dropTableScript.

    If needed you can use a persitence.xml and persitance unit name instead. Just say something
    and I post the code too.

    import java.util.Collection;
    import java.util.Properties;
    
    import org.hibernate.cfg.AnnotationConfiguration;
    import org.hibernate.dialect.Dialect;
    import org.hibernate.ejb.Ejb3Configuration;
    
    /**
     * SQL Creator for Tables according to JPA/Hibernate annotations.
     *
     * Use:
     *
     * {@link #createTablesScript()} To create the table creationg script
     *
     * {@link #dropTablesScript()} to create the table destruction script
     * 
     */
    public class SqlTableCreator {
    
        private final AnnotationConfiguration hibernateConfiguration;
        private final Properties dialectProps;
    
        public SqlTableCreator(final Collection> entities) {
    
            final Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
            for (final Class entity : entities) {
                ejb3Configuration.addAnnotatedClass(entity);
            }
    
            dialectProps = new Properties();
            dialectProps.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
    
            hibernateConfiguration = ejb3Configuration.getHibernateConfiguration();
        }
    
        /**
         * Create the SQL script to create all tables.
         * 
         * @return A {@link String} representing the SQL script.
         */
        public String createTablesScript() {
            final StringBuilder script = new StringBuilder();
    
            final String[] creationScript = hibernateConfiguration.generateSchemaCreationScript(Dialect
                    .getDialect(dialectProps));
            for (final String string : creationScript) {
                script.append(string).append(";\n");
            }
            script.append("\ngo\n\n");
    
            return script.toString();
        }
    
        /**
         * Create the SQL script to drop all tables.
         * 
         * @return A {@link String} representing the SQL script.
         */
        public String dropTablesScript() {
            final StringBuilder script = new StringBuilder();
    
            final String[] creationScript = hibernateConfiguration.generateDropSchemaScript(Dialect
                    .getDialect(dialectProps));
            for (final String string : creationScript) {
                script.append(string).append(";\n");
            }
            script.append("\ngo\n\n");
    
            return script.toString();
        }
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you help me look for a way to convert char into 8x8 binary
Hello I am having a hard time making this UI element look the way
I can create an IISWebVirtualDir or IISWebVirtualDirSetting with WMI, but I've found no way
Is there a way to look for a pattern in aspx/ascx files and replace
Is there a way to look through the cache for all objects in the
Is there a way that I manually have a user look up the current
Is there any way to see what a control will look like in the
I recently realized that the way my app icon and text look in the
What's is the proper way to change to background of JFrame with Sea-Glass Look
As I look into documentation of GKScore and GKLeaderboard, there is no way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.