I am using Hibernate 3.1
Following files are in my lib folder
antlr-2.7.5H3.jar
antlr.license.txt
cglib-nodep-2.1_2.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
hibernate3.jar
hsqldb.jar
jdbc2_0-stdext.jar
jdbc2_0-stdext.licence.txt
jta.jar
lib.txt
log4j-1.2.11.jar
mysql-connector-java-3.0.17-ga-bin.jar
following files are in my src folder
hibernate.cfg.xml
hibernate.properties log4j.properties src.txt
TestUser .java user.hbm.xml User.java
I get the following message when I run ant
Buildfile: build.xml
clean:
[delete] Deleting directory C:\TEMP\test3\bin
[mkdir] Created dir: C:\TEMP\test3\bin
copy-resources:
[copy] Copying 5 files to C:\TEMP\test3\bin
compile:
[javac] Compiling 2 source files to C:\TEMP\test3\bin
run:
[java] INFO - Hibernate 3.1 rc1
[java] INFO - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.MySQLMyISAMDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.show_sql=true, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
[java] INFO - using java.io streams to persist binary types
[java] INFO - using CGLIB reflection optimizer
[java] INFO - using JDK 1.4 java.sql.Timestamp handling
[java] INFO - configuring from resource: /hibernate.cfg.xml
[java] INFO - Configuration resource: /hibernate.cfg.xml
[java] INFO - Reading mappings from resource: user.hbm.xml
[java] INFO - Mapping class: User -> users
[java] INFO - Configured SessionFactory: null
[java] INFO - processing extends queue
[java] INFO - processing collection mappings
[java] INFO - processing association property references
[java] INFO - processing foreign key constraints
[java] INFO - Using Hibernate built-in connection pool (not for production use!)
[java] INFO - Hibernate connection pool size: 10
[java] INFO - autocommit mode: false
[java] INFO - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/test
[java] INFO - connection properties: {user=root, password=****}
[java] INFO - RDBMS: MySQL, version: 4.1.14-nt
[java] INFO - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.6 ( $Date: 2004/12/09 15:57:25 $, $Revision: 1.27.4.52 $ )
[java] INFO - Using dialect: org.hibernate.dialect.MySQLDialect
[java] INFO - Using default transaction strategy (direct JDBC transactions)
[java] INFO - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[java] INFO - Automatic flush during beforeCompletion(): disabled
[java] INFO - Automatic session close at end of transaction: disabled
[java] INFO - JDBC batch size: 15
[java] INFO - JDBC batch updates for versioned data: enabled
[java] INFO - Scrollable result sets: enabled
[java] INFO - JDBC3 getGeneratedKeys(): enabled
[java] INFO - Connection release mode: null
[java] INFO - Maximum outer join fetch depth: 1
[java] INFO - Default batch fetch size: 1
[java] INFO - Generate SQL with comments: disabled
[java] INFO - Order SQL updates by primary key: disabled
[java] INFO - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[java] INFO - Using ASTQueryTranslatorFactory
[java] INFO - Query language substitutions: {no='N', yes='Y'}
[java] INFO - Second-level cache: enabled
[java] INFO - Query cache: disabled
[java] INFO - Cache provider: org.hibernate.cache.HashtableCacheProvider
[java] INFO - Optimize cache for minimal puts: disabled
[java] INFO - Cache region prefix: hibernate.test
[java] INFO - Structured second-level cache entries: disabled
[java] INFO - Echoing all SQL to stdout
[java] INFO - Statistics: disabled
[java] INFO - Deleted entity synthetic identifier rollback: disabled
[java] INFO - Default entity-mode: POJO
[java] INFO - building session factory
[java] INFO - Not binding factory to JNDI, no JNDI name configured
[java] INFO - Running hbm2ddl schema update
[java] INFO - fetching database metadata
[java] INFO - updating schema
[java] INFO - processing extends queue
[java] INFO - processing collection mappings
[java] INFO - processing association property references
[java] INFO - processing foreign key constraints
[java] INFO - table found: .users
[java] INFO - columns: [lastname, firstname, id]
[java] INFO - foreign keys: []
[java] INFO - indexes: [primary]
[java] INFO - schema update complete
[java] INFO - cleaning up connection pool: jdbc:mysql://localhost/test
[java] INFO - Checking 0 named queries
[java] Hibernate:
[java] insert
[java] into
[java] users
[java] (FIRSTNAME, LASTNAME, ID)
[java] values
[java] (?, ?, ?)
BUILD SUCCESSFUL
Total time: 4 seconds
mysql> select * from users;
Empty set (0.00 sec)
My user class is
public class User
{
private int id;
private String firstName;
private String lastName;
public User(){
super();
this.firstName=null;
this.lastName=null;
this.id = 0;
}
/*
public User(int id, String firstName, String lastName){
this.id =id;
this.firstName = firstName;
this.lastName = lastName;
}
*/
public int getId(){
return this.id;
}
public String getFirstName( ){
return this.firstName;
}
public String getlastName(){
return this.lastName;
}
public void setId(int id){
this.id = id;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}
public void setLastName(String lastName){
this.lastName = lastName;
}
};
my test user class is
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
class TestUser
{
public TestUser(){
super();
}
public static void main(String[] args)
{
Session session = null;
User user = new User();
user.setFirstName("Farid");
user.setLastName("Ghafour");
user.setId(3);
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
session.save(user);
}// end try
catch(Exception e){
System.out.println(e.getMessage());
}//end catch
finally{
session.flush();
session.close();
}
} //end main
} //end class
hibernate.cfg.xml file contains
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="user.hbm.xml"/>
</session-factory>
</hibernate-configuration>
user.hbm.xml contains
<?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>
<class name="User" table="users" >
<id name="id" type="int" column="ID" >
<generator class="assigned"/>
</id>
<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
</class>
</hibernate-mapping>
|