my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes Exception while running hibernate - nubie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Exception while running hibernate - nubie" Watch "Exception while running hibernate - nubie" New topic
Author

Exception while running hibernate - nubie

Raghav Sidhanti
Greenhorn

Joined: Oct 09, 2009
Posts: 3
Hi,

I am new to hibernate. I am trying to run a simple Java program in Maven using hibernate but I keep getting the following error.

+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - org.hibernate.testapp:hibernate-test-app:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [org.codehaus.mojo:exec-maven-plugin:1.1.1:java]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing exec:java
[INFO] No goals needed for project - skipping
[WARNING] While downloading javassist:javassist:3.0
This artifact has been relocated to jboss:javassist:3.0.


[INFO] [exec:java {execution: default-cli}]
16 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
16 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.Environment - hibernate.properties not found
16 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
16 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
63 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
63 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
125 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Person.hbm.xml
188 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.hibernate.testapp.Person -> Person
204 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
235 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
235 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 10
235 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
250 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/test
250 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
454 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.1.36-community
454 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.10 ( Revision: ${svn.Revision} )
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
516 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.NoCacheProvider
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
532 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
563 [org.hibernate.mainpackage.HibernateTestApp.main()] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. null

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured while executing the Java class. null
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:338)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:283)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at org.hibernate.mainpackage.HibernateTestApp.main(HibernateTestApp.java:37)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Fri Oct 09 12:46:58 CDT 2009
[INFO] Final Memory: 5M/11M
[INFO] ------------------------------------------------------------------------
704 [Finalizer] INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:mysql://localhost/test

My code is as follows:
(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>

<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/test</property>
<property name="connection.username">root</property>
<property name="connection.password">raghav</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">10</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's current session context -->
<property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</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>

<mapping resource="Person.hbm.xml"/>

</session-factory>

</hibernate-configuration>
****************************************
(Person.hbm.xml)


<?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="org.hibernate.testapp.Person" table="Person">
<id name="id" type="long" column="id">
<generator class="assigned"/>
</id>
<property name="firstName">
<column name="FirstName"/>
</property>
<property name="lastName">
<column name="LastName"/>
</property>
<property name="companyName">
<column name="CompanyName"/>
</property>
<property name="city">
<column name="City"/>
</property>
<property name="zipCode">
<column name="ZipCode"/>
</property>

</class>


</hibernate-mapping>


*********************************************************
(org.hibernate.testapp.Person.java)

package org.hibernate.testapp;

public class Person {

private long id;
private String firstName;
private String lastName;
private String companyName;
private String city;
private String zipCode;

public Person(){

}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getCompanyName() {
return companyName;
}

public void setCompanyName(String companyName) {
this.companyName = companyName;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getZipCode() {
return zipCode;
}

public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}



}

**************************************************
(org.hibernate.mainpackage.HibernateTestApp.java)

package org.hibernate.mainpackage;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.testapp.Person;

public class HibernateTestApp {

public static void main(String args[]){
Session session;

try{

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();

Transaction tx = session.beginTransaction();
System.out.println("Inserting new records");
Person person = new Person();

person.setFirstName("Raghav");
person.setLastName("Sidhanti");
person.setCompanyName("Company");
person.setCity("Chicago");
person.setZipCode("60602");

session.save(person);
tx.commit();
System.out.println("Done");

}catch(Exception e){
System.out.println(e.getMessage());

}finally{
session.flush();
session.close();
}
}

}


Can some one please help me out?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Raghav Sidhanti
Greenhorn

Joined: Oct 09, 2009
Posts: 3
Hi David,

Thanks for trying to help. I was able to solve the problem by myself. It was an issue with my maven dependencies.
I will use the code tags in my next posts.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception while running hibernate - nubie
 
Similar Threads
Hibernate: Mapping a sequence to a serial (autoincr) field (Postgresql)
SQLGrammarException
Strange Error
Not able to update or save a object to database. please help.
[Help] Null Pointer Exception in session.flush() Hibernate