• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

hibernate

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am getting nullpoiter exception while executing below code. I m unable to figure out why file is not configured. please anyone can help me.

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is null (NullPointerExceptions always have a line number to tell you)?

Any exception further up the log?
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paul,
I am getting below exeception & I am new to Hibernate please any one can help me

org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1402)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1424)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at mypack.ViewEmployee.main(ViewEmployee.java:22)

while executing below 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="mypack.Employee" table="emp1234">
<id name="eid" column="eid">
<generator class="assigned"/>
</id>

<property name="ename">
<column name="ename" />
</property>
<property name="esal">
<column name="esal"/>
</property>
</class>
</hibernate-mapping>



<?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="current_session_context_class">thread</property>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="hibernate.connection.url">jdbc:db2:DEMO1</property>
<property name="hibernate.connection.username">nimesh.hindocha</property>
<property name="hibernate.connection.password">hardwork@321</property>
<!-- <property name="hibernate.connection.pool_size">10</property> -->
<property name="show_sql">true</property>
<property name="hibernate.dialect">hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>



package mypack;

public class Employee
{
public int eid,esal;
public String ename ;

public Employee()
{
}
public Employee(int eid,String ename,int esal)
{
this.eid=eid;
this.ename=ename;
this.esal=esal;
}
public int getEid() {
return eid;
}
public void setEid(int eid) {
this.eid = eid;
}
public int getEsal() {
return esal;
}
public void setEsal(int esal) {
this.esal = esal;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}

}
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
Please any help..
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


org.hibernate.HibernateException: /hibernate.cfg.xml not found


Where did you put your config file?
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paul,
I have placed my hibernate.cfg.xml in default project structure of java project in eclipse editor
src---->mypack----->hibernate.cfg.xml
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paul,
I have placed my hibernate.cfg.xml in default project structure of java project in eclipse editor
src---->mypack----->hibernate.cfg.xml
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It needs to be in the default package for your applciation, i.e. it needs to be in the route folder of wherever your class files are. Eclipse should move it there automatically when it compiles your applciation so if you move it out of mypack and into src it should work.

If you want to specify a different place for your configuration file to live have a look at the methods in the Configuration class.
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
I have put my configuration file in src folder as said by you but same problem remains.
Any other solution please do specify.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you hibernate.cfg.xml file is in the route folder where your class files have been compiled to?
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Problem is due to exception thrown class files are not generated.
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
I am sending the image of project structure i hope this might help to solve the problem.

Filename: PS.bmp
Description: Project Structure
File size: 972 Kbytes
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nimesh hindocha wrote:Hi Paul,
Problem is due to exception thrown class files are not generated.



So the project doesn't compile? What does that exception say?
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at ViewEmployees.main(ViewEmployees.java:22)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 2 more
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at ViewEmployees.main(ViewEmployees.java:22)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 2 more
 
nimesh hindocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Now i am able to configure but exception is thrown while query execution.Below is exception
inside try
16 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.0.SP1
32 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
32 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
32 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
110 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
110 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
204 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Employee.hbm.xml
297 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Employee -> emp1234
329 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
391 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
391 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
391 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
500 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.ibm.db2.jcc.DB2Driver at URL: jdbc:db2:emp1234
500 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=nimesh.hindocha, password=****}
3329 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: DB2/NT, version: SQL09071
3329 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: IBM DB2 JDBC Universal Driver Architecture, version: 3.4.65
3375 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.DB2Dialect
3375 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
3375 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
3375 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
3375 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
3375 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
3391 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
3391 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
3438 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
3672 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
after configure
Hibernate: select employee0_.eid as eid0_, employee0_.ename as ename0_, employee0_.esal as esal0_ from emp1234 employee0_
4204 [main] WARN org.hibernate.jdbc.AbstractBatcher - exception clearing maxRows/queryTimeout
com.ibm.db2.jcc.b.SqlException: [ibm][db2][jcc][10120][10943] Invalid operation: statement is closed.
at com.ibm.db2.jcc.b.hh.A(hh.java:2416)
at com.ibm.db2.jcc.b.hh.getMaxRows(hh.java:615)
at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:298)
at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1822)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at ViewEmployees.main(ViewEmployees.java:27)
4204 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: -4499, SQLState: 58009
4204 [main] ERROR org.hibernate.util.JDBCExceptionReporter - [ibm][db2][jcc][t4][2034][11148] Execution failed due to a distribution protocol error that caused deallocation of the conversation.
A DRDA Data Stream Syntax Error was detected. Reason: 0x1.
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at ViewEmployees.main(ViewEmployees.java:27)
Caused by: com.ibm.db2.jcc.b.DisconnectException: [ibm][db2][jcc][t4][2034][11148] Execution failed due to a distribution protocol error that caused deallocation of the conversation.
A DRDA Data Stream Syntax Error was detected. Reason: 0x1.
at com.ibm.db2.jcc.c.ab.l(ab.java:931)
at com.ibm.db2.jcc.c.ab.c(ab.java:365)
at com.ibm.db2.jcc.c.ab.v(ab.java:1134)
at com.ibm.db2.jcc.c.db.b(db.java:81)
at com.ibm.db2.jcc.c.t.b(t.java:71)
at com.ibm.db2.jcc.c.tb.c(tb.java:225)
at com.ibm.db2.jcc.b.ih.bb(ih.java:1921)
at com.ibm.db2.jcc.b.ih.eb(ih.java:1998)
at com.ibm.db2.jcc.b.ih.d(ih.java:2439)
at com.ibm.db2.jcc.b.ih.V(ih.java:492)
at com.ibm.db2.jcc.b.ih.executeQuery(ih.java:475)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
... 8 more
in catch blk



Please do reply paul......i am looking for you.
 
Run away! Run away! Here, take this tiny ad with you:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic