These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate doesn't create tables on PostgreSQL
PostPosted: Wed Aug 27, 2008 6:01 am 
Newbie

Joined: Fri Aug 01, 2008 9:14 am
Posts: 4
Hi everybody,

I'm using Hibernate via JPA on JBoss 4.2.3 with PostgreSQL 8.3 as a backend. I'm tying to persist a very simple POJO looking like this:


Code:
@Entity
public class Player {
   private String nickname;
   private int id = -1;
   
   @Id
   public int getId() {
      return id;
   }
   public void setId(int id) {
      this.id = id;
   }
   public String getNickname() {
      return nickname;
   }
   public void setNickname(String nickname) {
      this.nickname = nickname;
   }

}



Everything works fine when starting up the server, it gets a connection, but when I call em.persist() the database log and Hibernate are reporting that the table doesn't exist.

Code:
ERROR [AbstractFlushingEventListener]11:35:30,054 ERROR [JDBCExceptionReporter] ERROR: relation "player" does not exist
11:35:30,054 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update


postgres-ds.xml
Code:
<datasources>
  <local-tx-datasource>
    <jndi-name>PostgresDS</jndi-name>
    <connection-url>jdbc:postgresql://127.0.0.1:5432/db1</connection-url>
    <driver-class>org.postgresql.Driver</driver-class>
    <user-name>user1</user-name>
    <password>****</password>
    <min-pool-size>1</min-pool-size>
     <max-pool-size>4</max-pool-size>
  </local-tx-datasource>
</datasources>


Is it a misunderstanding on my side? I always thought that Hibernate or any other JPA-Provider would take care of "everything" including creation of the database tables and columns?

If I create the table myself everything works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 6:21 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Hibernate will not take care of everything. At least not automatically. There are tools that you can use to create the tables (see http://www.hibernate.org/hib_docs/v3/re ... guide.html) but you still have to create at least an empty database.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.