Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data insert error

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to run tutorial
here is the config file



here is the hbm file


here is the contact class


here is the main class


but i got this error
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)


when i debug this class it goes till session.flush(); line at finally block.
after session.close(); line it gives same error.
 
satishbsk kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think hibernate unable to create session.. check the hibernate.cfg.xml file path
rgds,
Satish
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes,i also know that .but i can't find where the error is?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aruna sameera wrote:yes,i also know that .but i can't find where the error is?


Probably because, the exception is being eaten up:




Print the entire stacktrace and see what it contains.
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i update the main class as below.Add the e.printStackTrace()

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then i add the break point to line numbers 20,23 ,32 and 36.then i starts debugging.
first it stop at line number 20.
then i press F6.Then it jubp to 36 directly.
that is mean it can't creat session.so where is the error?
 
Gavi jadz Grandea
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is mean it can't creat session.so where is the error?


you will not see the error because of the try-catch block as that is its purpose.

i would suggest deleting the try-catch so that you will see the error on the console.

first it stop at line number 20.
then i press F6.Then it jubp to 36 directly.


probably you have the problem on the Configuration() part where it cannot create a SessionFactory.

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes.i did what you said.delete the try catch block.
now this is the error.

Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0rc1
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: contact.hbm.xml
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: roseindia.tutorial.hibernate.Contact -> CONTACT
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Sep 13, 2009 11:36:19 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Sep 13, 2009 11:36:19 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Sep 13, 2009 11:36:20 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Sep 13, 2009 11:36:20 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Sep 13, 2009 11:36:20 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 10
Sep 13, 2009 11:36:20 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Sep 13, 2009 11:36:20 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/hibernatetutorial
Sep 13, 2009 11:36:20 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Sep 13, 2009 11:36:20 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Sep 13, 2009 11:36:20 PM 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 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: enabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Sep 13, 2009 11:36:20 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Sep 13, 2009 11:36:20 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Sep 13, 2009 11:36:20 PM net.sf.ehcache.config.Configurator configure
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/PROJECT/eclips/AAAAA/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/SystemException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.id.IdentifierGeneratorFactory.class$(IdentifierGeneratorFactory.java:25)
at org.hibernate.id.IdentifierGeneratorFactory.<clinit>(IdentifierGeneratorFactory.java:76)
at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:111)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:166)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:21)

 
Ranveer K Kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aruna sameera wrote:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/SystemException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.id.IdentifierGeneratorFactory.class$(IdentifierGeneratorFactory.java:25)
at org.hibernate.id.IdentifierGeneratorFactory.<clinit>(IdentifierGeneratorFactory.java:76)
at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:111)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:166)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:21)



it seems that your your driverclass(mysql) file not in the classpath liabrary.

please check..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should also probably avoid the roseindia tutorials. They are pretty buggy.
 
Gavi jadz Grandea
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I agree. Your missing your driverclass ( com.mysql.jdbc.Driver ) and that's why you can't create a SessionFactory.
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gavi jadz Grandea wrote:
I agree. Your missing your driverclass ( com.mysql.jdbc.Driver ) and that's why you can't create a SessionFactory.


I don't. javax.transaction.SystemException is no class I would look for in a JDBC-Driver. I think he is missing jta.jar or if he uses JBoss jboss-j2ee.jar.
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.now it may seems working.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
Done
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)


but it doesn't insert data to the data base.But it doesn't have any compiler error?
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using mysql.
here is where it installed.
"C:\Program Files\MySQL\"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic