Configuration of the Hibernate!

Asked

Viewed 44 times

5

Hello I’m having a difficulty regarding a Hibernate configuration hibernate.hbm2ddl.import_files i believe q am doing everything right to find the sql path, I am using the same to insert some data into a tables as soon as the database is created

            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/usuarios" ></property>
            <property name="javax.persistence.jdbc.user" value="postgres" />
            <property name="javax.persistence.jdbc.password" value="" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.connection.shutdown" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.hbm2ddl.import_files" value="/resources/sql/init.sql"/>
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true"/>

this init.sql is in the web/WEB-INF/Resources/sql/init.sql folder (default Maven)

inserir a descrição da imagem aqui

I managed to do it this way: I put persistence src/main/resource/META-INF/sql/dados.sql and the Presoperty were as follows

<property name="hibernate.hbm2ddl.import_files" value="META-INF/sql/dados.sql"/>
 <property name="hibernate.hbm2ddl.auto" value="create"/>

persistence is in the Resource folder

1 answer

1


I believe it would be right to change the directory of your scripts to src/META-INF/sql/init.sql would be on the same level as your archive persistence.xml

In your persistence.xml file you would get these settings:

....
<property name="javax.persistence.schema-generation.create-source" value="metadata" />
<property name="javax.persistence.sql-load-script-source" value="META-INF/sql/init.sql"/>
....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.