-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Configuration problem
PostPosted: Thu Aug 12, 2010 10:45 am 
Newbie

Joined: Thu Aug 12, 2010 10:06 am
Posts: 4
Hi,
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
package mypack;

import org.hibernate.Transaction;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
//import mypack.Employee;
import java.util.List;
import java.util.Iterator;
import org.hibernate.Query;

public class ViewEmployee
{
public static void main(String[] args)
{

Session session = null;
SessionFactory factory;
try
{

factory=new Configuration().configure().buildSessionFactory();//line 22

session=factory.openSession();

Transaction tr=session.beginTransaction();

Query query=session.createQuery("from Employee e");

List list=query.list();

Iterator iter=list.iterator();

while(iter.hasNext())
{
System.out.println(iter.next());
}
tr.commit();

}
catch(Exception e)
{
e.printStackTrace();
}


}

}


<?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;
}

}


Top
 Profile  
 
 Post subject: Re: Configuration problem
PostPosted: Fri Aug 13, 2010 12:21 am 
Newbie

Joined: Thu Aug 12, 2010 10:06 am
Posts: 4
Hi Anish,
It is default folder structure of java project in eclipse editor.
Any solution please


Top
 Profile  
 
 Post subject: Re: Configuration problem
PostPosted: Fri Aug 13, 2010 12:37 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi Nimesh,

The problem is that it is not able to find with in the project.

Place the cfg file root of src\ folder. Hope it would resolve. Also In configuration file specify the full path of the mapping file . Get back what happened.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Configuration problem
PostPosted: Fri Aug 13, 2010 3:12 am 
Newbie

Joined: Thu Aug 12, 2010 10:06 am
Posts: 4
Hi Shynate26,
I placed cfg file to root of src\ folder still problem is not resolved

org.hibernate.HibernateException: /hibernate/src/mypack/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 mypack.ViewEmployee.main(ViewEmployee.java:22)


Top
 Profile  
 
 Post subject: Re: Configuration problem
PostPosted: Fri Aug 13, 2010 5:05 am 
Newbie

Joined: Thu Aug 12, 2010 10:06 am
Posts: 4
Hi,
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

Code:
package mypack;

[list]import org.hibernate.Transaction;
import org.hibernate.Session;
import org.hibernate.SessionFactory;[/list]
import org.hibernate.cfg.Configuration;
//import mypack.Employee;
import java.util.List;
import java.util.Iterator;
import org.hibernate.Query;

public class ViewEmployee
{
public static void main(String[] args)
{

Session session = null;
SessionFactory factory;
try
{

factory=new Configuration().configure().buildSessionFactory();//line 22

session=factory.openSession();

Transaction tr=session.beginTransaction();

Query query=session.createQuery("from Employee e");

List list=query.list();

Iterator iter=list.iterator();

while(iter.hasNext())
{
System.out.println(iter.next());
}
tr.commit();

}
catch(Exception e)
{
e.printStackTrace();
}


}

}


<?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;
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.