I have tried to run my first Hibernate & Jboss AS-7 in jboss development studio IDE. so I started with a simple example and after a week struggling with it, now I can say I know nothing about following error(I am using postgresql as database)
stack trace is:
12:18:14,080 WARN [org.hibernate.engine.jdbc.internal.JdbcServicesImpl] (http--0.0.0.0-8080-1) HHH000342: Could not obtain connection to query metadata : No suitable driver found for jdbc:postgresql://localhost:5432/postgres
12:18:14,081 INFO [org.hibernate.dialect.Dialect] (http--0.0.0.0-8080-1) HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
12:18:14,081 INFO [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (http--0.0.0.0-8080-1) HHH000422: Disabling contextual LOB creation as connection was null
12:18:14,082 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (http--0.0.0.0-8080-1) HHH000399: Using default transaction strategy (direct JDBC transactions)
12:18:14,083 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (http--0.0.0.0-8080-1) HHH000397: Using ASTQueryTranslatorFactory
12:18:14,088 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (http--0.0.0.0-8080-1) HHH000227: Running hbm2ddl schema export
12:18:14,088 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (http--0.0.0.0-8080-1) HHH000231: Schema export unsuccessful: java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/postgres
============================================================================
my hibernate.cfg.xml is:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration SYSTEM "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.password">amir</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="hibernate.connection.username">postgres</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.listeners.envers.autoRegister">false</property>
</session-factory>
my persistence.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<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="Hiber_test" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/Hiber_testDatasource</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postgres"/>
<property name="hibernate.connection.username" value="postgres"/>
<property name="hibernate.connection.password" value="amir"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/Hiber_testEntityManagerFactory"/>
</properties>
</persistence-unit>
</persistence>
============================================================================ my java program is:
try {
Class.forName("org.postgresql.Driver");
//on classpath
} catch(ClassNotFoundException e) {
// not on classpath
System.out.println("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK" + e);
}
Configuration cfg = new Configuration()
.addResource("Event.hbm.xml").configure();
SessionFactory sessions = cfg.buildSessionFactory();
Session session = sessions.openSession();
=============================================================================
I really appreciate any person who can help me solve this issue.``