Hello All
I downloaded and installed Hibernate.
I created the hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/gunnar</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">password</property>
        <!-- <property name="hibernate.default_schema">public</property> -->
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
         <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
        <!-- Disable the second-level cache  -->
        <!--  <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> -->
            
        <!-- Drop and re-create the database schema on startup -->
        <!--<property name="hbm2ddl.auto">update</property> -->
        <mapping resource="hello/Teste.hbm.xml"/>
        
    </session-factory>
</hibernate-configuration>
The model Teste class:
Code:
package hello;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
public class Teste {
    private int id;
    public int getId() {
   return id;
    }
    public void setId(int id) {
   this.id = id;
    }
}
the hbm file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hello">
  <class name="Teste" table="teste">
     <id name="id" column="id">
       <generator class="native"/>            
    </id>     
  </class>
</hibernate-mapping>
The Util class:
Code:
package hello;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
public class HibernateSAUtil {
   private static final SessionFactory sessionFactory;
   static {
      try {
         sessionFactory = new Configuration().configure().buildSessionFactory();
      } catch (Throwable ex) {
         // Log exception!
         throw new ExceptionInInitializerError(ex);
      }
   }
   public static Session getSession() throws HibernateException {
      return sessionFactory.openSession();
   }
}
and the main class:
Code:
package hello;
import org.hibernate.Session;
public class Main {
   public static void main(String[] args) {
      HibernateSAUtil util = new HibernateSAUtil();
      Session session = util.getSession();
      
      
   }
}
When I run the code from the Main class I get the following exception:
Code:
Exception in thread "main" java.lang.ExceptionInInitializerError
   at hello.HibernateSAUtil.<clinit>(HibernateSAUtil.java:18)
   at hello.Main.main(Main.java:7)
Caused by: java.lang.AbstractMethodError: org.postgresql.jdbc2.Jdbc2DatabaseMetaData.supportsGetGeneratedKeys()Z
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:123)
   at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
   at hello.HibernateSAUtil.<clinit>(HibernateSAUtil.java:15)
   ... 1 more
I can connect to the database using jdbc without problems.
I really have no idea what I am doing wrong here....any help is welcome.
best regards