Comment générer Envers schéma de base de données avec org.mise en veille prolongée.outil de.EnversSchemaGenerator?

StackOverflow https://stackoverflow.com//questions/9647528

  •  10-12-2019
  •  | 
  •  

Question

J'ai mis à jour Hibernate pour la 4.1.1.Version finale.Selon la documentation Il y a 2 façons de générer un schéma de base de données:

  1. Tâche Ant org.hibernate.tool.ant.EnversHibernateToolTask.
  2. Exécuter org.hibernate.tool.EnversSchemaGenerator à partir de Java.

Hibernate tools ne fonctionne pas avec Hibernate-4.1.1.Final.Il a un bug de blocage.

Je n'ai trouvé que notes de version et un cas de test.Alors, comment puis-je utiliser org.hibernate.tool.EnversSchemaGenerator avec mon persistence.xml et Maven?

Mise à jour:

Trouvée en rapport fil sur le Hibernate forum.Il semble qu'il n'y a pas de réponse à ma question pourtant.

Était-ce utile?

La solution

Juplo a créé Plugin Maven pour Hibernate 4.Le plugin prend en charge le schéma d'exportation, y compris Envers.L'exemple ci-dessous.Vérifier officiel de configuration du plugin documentation pour obtenir une explication pour les options utilisées.

Le plugin génère schema.sql fichier dans le Maven /target répertoire test objectif.Ou vous pouvez exécuter manuellement hibernate4:export objectif mettre à jour le fichier.

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>de.juplo</groupId>
                <artifactId>hibernate4-maven-plugin</artifactId>
                <version>1.0.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>export</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <envers>true</envers>
                    <format>true</format>
                    <delimiter>;</delimiter>
                    <force>true</force>
                    <type>CREATE</type>
                    <target>SCRIPT</target>
                    <hibernateDialect>org.hibernate.dialect.PostgreSQL9Dialect</hibernateDialect>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Autres conseils

Vous n'avez pas besoin de Fourmi ou Hibernate tools.Il est assez facile de simplement utiliser le EnversSchemaGenerator directement, comme ceci:

Configuration config = new Configuration();

//make sure you set the dialect correctly for your database (oracle for example below)
config.setProperty("hibernate.dialect","org.hibernate.dialect.Oracle10gDialect");

//add all of your entities
config.addAnnotatedClass(MyAnnotatedEntity.class);

SchemaExport export = new EnversSchemaGeneHator(config).export();
export.execute(true, false, false, false);

Vous pouvez aussi lui donner un nom du fichier à écrire, mais le code ci-dessus va d'impression vers le syslog de toute façon.

Le suivant a fonctionné pour moi:

public static void main(String[] args) {
    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure("persistenceUnit", null);
    jpaConfiguration.buildMappings();
    Configuration hibernateConfiguration = jpaConfiguration.getHibernateConfiguration();
    AuditConfiguration.getFor(hibernateConfiguration);
    EnversSchemaGenerator esg = new EnversSchemaGenerator(hibernateConfiguration);
    org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export();
    se.setOutputFile("sql/schema.sql");
    se.setFormat(true);
    se.setDelimiter(";");
    se.drop(true, false);
    se.create(true, false);
}

J'ai eu le même problème.Maintenant, il est un Hibernate 4 Outils version:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-tools</artifactId>
        <version>4.0.0-CR1</version>
    </dependency>

Mais cette Fourmi fragment de ne pas exporter la vérification des tables, seule la "base" des tables:

<target name="schema-export">
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.EnversHibernateToolTask" classpathref="classpath"/>
    <hibernatetool destdir="sql">
        <classpath refid="classpath"/>
        <jpaconfiguration persistenceunit="persistenceUnit"/>
        <hbm2ddl export="false" create="true" drop="true" format="true" outputfilename="schema.sql"/>
    </hibernatetool>
</target>

Même avec ce code:Seulement "de base", pas de "_aud" tables:

public static void main(String[] args) {
    Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure("persistenceUnit", null);
    Configuration hibernateConfiguration = jpaConfiguration.getHibernateConfiguration();
    AuditConfiguration.getFor(hibernateConfiguration);
    EnversSchemaGenerator esg = new EnversSchemaGenerator(hibernateConfiguration);
    org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export();
    se.setOutputFile("sql/schema.sql");
    se.setFormat(true);
    se.setDelimiter(";");
    se.drop(true, false);
    se.create(true, false);
}

Êtes-vous toujours intéressé?Je vous tiens au courant si je trouve comment résoudre le problème.Peut-être que quelqu'un d'autre a des conseils à nous donner?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top