Hi Froestel,
The strange errors ultimately removed...But it was replaced by another errors.
Let me first tell you the jar files I am using are...
mysql.jar
slf4j-api-1.5.2.jar
slf4j-jdk14-1.5.2.jar
hibernate3.jar
dom4j-1.6.1.jar
javassist-3.4.ga.jar
commons-collections-3.2.1.jar
jta-1.1.jar
antlr-2.7.6.jar
commons-logging-1.1.1.jar
cglib-2.2.jar.
Now the files are..
Code:
///TestPerson.java
package com.sample;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
public class TestPerson {
public static void main(String[] args) {
Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
createPerson(session);
queryPerson(session);
}
private static void queryPerson(Session session) {
Query query = session.createQuery("from person");
List <person>list = query.list();
java.util.Iterator<person> iter = list.iterator();
while (iter.hasNext()) {
person person = iter.next();
System.out.println("Person: \"" + person.getName() +
"\", " + person.getAge());
}
session.getTransaction().commit();
}
public static void createPerson(Session session) {
person person = new person();
person.setName("Barak");
person.setAge("91");
session.save(person);
}
}
//person.java
package com.sample;
import java.lang.*;
public class person {
String name;
String age;
private Long id;
public Long getId() {
return id;
}
private void setId(Long id) {
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getAge()
{
return age;
}
public void setAge(String age)
{
this.age = age;
}
}
///SessionFactoryUtil.java
package com.sample;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class SessionFactoryUtil {
private static SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
// sessionFactory = new Configuration().configure().buildSessionFactory();
Configuration c= new Configuration();
c.configure();
sessionFactory = c.buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
ex.printStackTrace();
}
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
}
//Person.hbm.xml
<?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="com.sample.person" table="Person">
<id name="name" column="name">
<generator class="native" />
</id>
<property name="name">
<column name="NAME" length="16" not-null="true" />
</property>
<property name="age">
<column name="AGE" length="16" not-null="true" />
</property>
</class>
</hibernate-mapping>
///hibernate.cfg.xml
<?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>
<!-- hibernate dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:MySQL://127.0.0.1:3306/mysql</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- Automatic schema creation (begin) === -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Simple memory-only cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class">thread</property>
<!-- ############################################ -->
<!-- # mapping files with external dependencies # -->
<!-- ############################################ -->
<mapping resource="com/sample/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The error I am getting is...
Sep 22, 2009 1:03:21 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.4.sp1
Sep 22, 2009 1:03:21 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Sep 22, 2009 1:03:21 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Sep 22, 2009 1:03:21 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Sep 22, 2009 1:03:21 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Sep 22, 2009 1:03:21 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Sep 22, 2009 1:03:21 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : com/sample/Person.hbm.xml
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.sample.person -> Person
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Sep 22, 2009 1:03:22 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Sep 22, 2009 1:03:22 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Sep 22, 2009 1:03:22 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Sep 22, 2009 1:03:22 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:MySQL://127.0.0.1:3306/mysql
Sep 22, 2009 1:03:22 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.51b-community-nt
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.8 ( Revision: ${svn.Revision} )
Sep 22, 2009 1:03:22 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
Sep 22, 2009 1:03:22 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
Sep 22, 2009 1:03:22 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Sep 22, 2009 1:03:22 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.HashtableCacheProvider
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Sep 22, 2009 1:03:22 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Sep 22, 2009 1:03:23 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/objectweb/asm/Type
java.lang.NoClassDefFoundError: org/objectweb/asm/Type
at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:180)
at net.sf.cglib.core.KeyFactory.<clinit>(KeyFactory.java:66)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at com.sample.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:18)
at com.sample.TestPerson.main(TestPerson.java:11)
Exception in thread "main" java.lang.NullPointerException
at com.sample.TestPerson.main(TestPerson.java:11)
Please let me know if you find any solution.
Thanks in advance
BUBI