Hi there,
I am trying to implement a simple application which is creating a contact and just saving it to the database (HsqlDB). This is what i have done ;
Code:
package com.hibproject.app;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import ap.Contact;
public class Test {
public static void main(String[] args) {
Session session = null;
Transaction tx = null;
Contact contact = new Contact();
contact.setFirstName("Firs");
contact.setLastName("las");
contact.setEmail("mail@mail.com");
try {
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
session = sessionFactory.openSession();
tx = session.beginTransaction();
session.save(contact);
session.flush();
tx.commit();
System.out.println("Done..");
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
finally {
System.out.println("Commited : " + tx.wasCommitted());
session.close();
}
}
}
The contact hbm is this :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="ap.Contact" table="book">
<id name="id" type="int" column="id">
<generator class="increment" />
</id>
<property name="firstName" type="string" column="fname"></property>
<property name="lastName" type="string" column="lname"></property>
<property name="email" type="string" column="email"></property>
</class>
</hibernate-mapping>
The cfg xml is this :
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.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:/media/LagerHaus/ProjectsDBS/ObssDB</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connecton.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!--mapping files-->
<mapping resource="ap/Contact.hbm.xml" />
</session-factory>
</hibernate-configuration>
And i am getting the output as the following :
Quote:
14 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
20 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
33 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
38 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
127 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
127 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
207 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : ap/Contact.hbm.xml
304 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: ap.Contact -> book
323 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
372 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
372 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 10
372 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
374 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:/media/LagerHaus/ProjectsDBS/ObssDB
374 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa}
1567 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: HSQL Database Engine, version: 1.8.0
1568 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
1637 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
1648 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
1652 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
1652 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
1652 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
1653 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
1653 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
1654 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
1654 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
1655 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
1656 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
1656 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
1656 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
1657 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
1657 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
1661 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
1661 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
1661 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
1661 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
1662 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
1662 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
1662 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
1662 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
1677 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
1678 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
1678 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
1678 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
1678 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
1721 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
1860 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
1865 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - Running hbm2ddl schema update
1865 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - fetching database metadata
1871 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - updating schema
1944 [main] INFO org.hibernate.tool.hbm2ddl.TableMetadata - table found: PUBLIC.BOOK
1944 [main] INFO org.hibernate.tool.hbm2ddl.TableMetadata - columns: [id, lname, email, fname]
1944 [main] INFO org.hibernate.tool.hbm2ddl.TableMetadata - foreign keys: []
1944 [main] INFO org.hibernate.tool.hbm2ddl.TableMetadata - indexes: []
1945 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - schema update complete
Hibernate: select max(id) from book
Hibernate: insert into book (fname, lname, email, id) values (?, ?, ?, ?)
Done..
Commited : true
I am not using hibernate.properties but when i saw the "20 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found" line i have added hibernate.properties with same values of the cfg.xml
It clear out the line above but the result is the same.
Nothing being inserted to my database. I couldn't see why ? Have an idea why?