3

I am having a project in which i have used jpa+hibernate. I am having a persistence.xml file and want it to create the tables in the database automatically.I have specified all the properties correctly. In the log it shows all the sql statements but still in the database there are no tables. Does anyone have a solution for this problem I have searched almost all the links related to my problem but nothing worked.

Here is my persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

        <persistence-unit name="pl4sms-persistence" >
        <provider>org.hibernate.ejb.HibernatePersistence</provider>


    <class>com.ecomm.pl4sms.persistence.entities.SampleBatch</class>
    <class>com.ecomm.pl4sms.persistence.entities.SampleMessage</class>



        <properties>
           <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/samplejpa"/>

        <property name="hibernate.connection.username" value="root"/>
        <property name="hibernate.connection.password" value="root"/>
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="create" />
          </properties>
    </persistence-unit>
</persistence>

This is what i get on console

16:35:48,881 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 23) HCANN000001: Hibernate Commons Annotations {4.0.4.Final} 16:35:49,069 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 23) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect 16:35:49,084 WARN [org.hibernate.dialect.H2Dialect] (ServerService Thread Pool -- 23) HHH000431: Unable to determine H2 database version, certain features may not work 16:35:49,225 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 23) HHH000397: Using ASTQueryTranslatorFactory 16:35:49,537 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 23) HHH000227: Running hbm2ddl schema export

user3588548
  • 45
  • 1
  • 6
  • are you using gui tool pgAdmin for postgres – singhakash Feb 05 '15 at 13:03
  • Yes i used pgAdmin to create database – user3588548 Feb 05 '15 at 13:07
  • Thats strange because create query is shown in console have you checked pgAdmin `PostgreSql->samplejpa->Schemas->public->Tables` for tables.if there is any problem it would be shown in console. – singhakash Feb 05 '15 at 14:11
  • Yes i did checked that but there are no tables... I am also confused why its not getting created – user3588548 Feb 05 '15 at 14:32
  • Did you ever resolve this problem? I would like to know what the problem was and the solution if possible. – Rob L Mar 29 '15 at 19:20
  • I have a similar problem - I specified a URL and driver for Oracle - but wildfly states "Using dialect: org.hibernate.dialect.H2Dialect" - and never connects to the external DB-Server. It uses the internal H2-Server and I dont know why.... – cljk Jul 15 '15 at 09:33

1 Answers1

0

The log clearly states that the tables are created. If there's an exception or something similar, you need to post it on your question.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • There are no exceptions...Thats what i am saying it shows that tables are created but there are no tables in the database that i created – user3588548 Feb 05 '15 at 13:02
  • They are created in the samplejpa database on your localhost PostgreSQL server. Add a trace log level on org.hibernate to validate the database URL. – Vlad Mihalcea Feb 05 '15 at 13:05
  • yes i created that database but there are not tables in samplejpa database..Problem is with wildfly as same configuration is working fine with testng – user3588548 Feb 05 '15 at 13:06
  • @ Vlad Mihalcea I checked postgres logs..When deployed on wildfly server Its not communicating with postgres as there is no log regarding tables creation ,But in case of testng it shows log in postgres log file. – user3588548 Feb 05 '15 at 14:25
  • You need to check the app logs, not the postgres logs. If the app logs say that the tables are created, then it means the DB connection is fine, and in that case you need to see what connection is in use. Could it be that it uses some other db settings, other than the ones you expect? – Vlad Mihalcea Feb 05 '15 at 14:43