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!

4
  • I think that is a case problem like this : stackoverflow.com/questions/11595599/… Commented Mar 2, 2015 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... Commented Mar 3, 2015 at 14:00
  • I mean this "Postgres (used to, not sure on the newer) convert table names to lower case." Commented Mar 3, 2015 at 14:15
  • @pL4Gu33: I got that, I just don't understand what I should do about it :( Commented Mar 4, 2015 at 13:14

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.