Автоматический генерируют схему данных от аннотируемых классов объекта JPA

Вы должны отправить endEditing: в рабочее окно, являющееся подклассом UIView

[[UIApplication sharedApplication].windows.firstObject endEditing:NO];
41
задан Steve Kuo 18 November 2008 в 00:09
поделиться

2 ответа

Генерация скрипта создания и удаления для заданных объектов JPA

Мы используем этот код для генерации операторов drop и create: Просто создайте этот класс со всеми классами сущностей и вызовите create / dropTableScript.

Если необходимо, вы можете вместо этого использовать persitence.xml и имя модуля persitance. Просто скажи что-нибудь и я тоже отправляю код.

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<Class<?>> 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();
    }
}
13
ответ дан 27 November 2019 в 00:49
поделиться

Вот объяснение того, как использовать класс SchemaExport гибернации, чтобы делать именно то, что вы хотите.

http://jandrewthompson.blogspot.com/2009/10/how -to-generate-ddl-scripts-from.html

6
ответ дан 27 November 2019 в 00:49
поделиться
Другие вопросы по тегам:

Похожие вопросы: