4

I'm just starting with hibernate and I have a simple configuration that gives me this error: "relation "userdetails" does not exist" when I try to first save the only class I have.


my hibernate.gfg.xml file:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">XXXX</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">
            org.hibernate.dialect.PostgreSQLDialect
        </property>

        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="show_sql">true</property>
        <property name="hdm2ddl.auto">create</property>

        <mapping class="hibernate.project.UserDetails"/>

    </session-factory>

</hibernate-configuration>

my only model class:

@Entity
public class UserDetails {

    @Id
    private int userId;
    private String userName;

    public int getUserId() {
        return userId;
    }
    public void setUserId(int userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }

my main:

public static void main(String[] args) {
        UserDetails user = new UserDetails();
        user.setUserId(1);
        user.setUserName("First User");

        Configuration config = new Configuration().configure();


        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

        SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);


        Session session=sessionFactory.openSession();
        session.beginTransaction();
        session.save(user);
        session.getTransaction().commit();
    }

any ideas? I've found similar questions but didn't help. thanks!

lou
  • 183
  • 1
  • 10
  • I think that is a case problem like this : http://stackoverflow.com/questions/11595599/querying-postgresql-using-hibernate-jpa-doesnt-find-table – pL4Gu33 Mar 02 '15 at 19:09
  • I don't see what I should change in my code respect to your example, I don't have annotations with names... – lou Mar 03 '15 at 14:00
  • I mean this "Postgres (used to, not sure on the newer) convert table names to lower case." – pL4Gu33 Mar 03 '15 at 14:15
  • @pL4Gu33: I got that, I just don't understand what I should do about it :( – lou Mar 04 '15 at 13:14

1 Answers1

2

The create property is incorrect : Use hbm2ddl instead of hdm2ddl

    <property name="hibernate.hbm2ddl.auto">create</property>

OR

    <property name="hbm2ddl.auto">create</property>

and not

hdm2ddl.auto

Seems to be typo at your end.

prit kalra
  • 319
  • 4
  • 18
  • This seems to be the difference between a basic config for mysql vs postgres, and the difference between working and not working. Mysql seems to not need an entry like this. Thanks. – Doomed Mind Jan 10 '17 at 10:40