0

This question seems to be repeated but i tried all possibilities i could do but not able to resolve this error. please help me i am beginner in Hibernate.

-FirstProject

--->src

 ------>myPackage --> Employee.java --> StoreData.java 

--->Employee.hbl.xml

--->hibernate.cfg.xml

Both xml files are under src folder and here my code goes

package mypackage; **public class Employee** { private int id; private String FirstName,LastName; public int getId() { return id; } public void setId(int 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; } } 

Employee.hbl.xml

<class name="mypackage.Employee" table="emp1000"> <id name="id"> <generator class="assigned"></generator> </id> <property name="firstName" column="fname" type="String"></property> <property name="lastName" column="lname" type="String"></property> </class> 

hibernate.cfg.xml

<session-factory> <property name="hbm2ddl.auto">update</property> <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property> <property name="connection.username">system</property> <property name="connection.password">12345</property> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <mapping resource="First/src/Employee.hbm.xml"/> </session-factory> 

StoreData.java

package mypackage; public class StoreData { public static void main(String[] args) { SessionFactory sF = new Configuration(). configure("/First/src/mypackage/hibernate.cfg.xml").buildSessionFactory(); Session session=sF.openSession(); Transaction t=session.beginTransaction(); Employee e1=new Employee(); e1.setId(115); e1.setFirstName("Madu"); e1.setLastName("biradar"); session.persist(e1); t.commit(); session.close(); System.out.println("successfully saved"); } } 

Thanks to all who would give any sort of suggestion...

7
  • i hope Employee.hbl.xml is a typo, you have mapped with name hbm, and file name is hbl, maybe just a type and is no related the eaxt issue, also post the complete stacktrace Commented Sep 9, 2014 at 6:44
  • does it solve your purpose or was just a type while posting the question Commented Sep 9, 2014 at 6:49
  • @it was my mistake in code itself and i corrected it but this time its showing another error as " TNS:listener does not currently know of SID given in connect descriptor The Connection descriptor used by the client was: localhost:1521:xe" Commented Sep 9, 2014 at 6:55
  • I have installed Oracle 11 g Enterprise Edition in my system. Commented Sep 9, 2014 at 6:57
  • answer posted for your acceptance Commented Sep 9, 2014 at 7:00

2 Answers 2

1

i hope Employee.hbl.xml is a typo, you have mapped with name hbm, and file name is hbl, maybe just a type and is no related the exact issue, also post the complete stacktrace

are you able to connect using below connection properties

<property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property> 
Sign up to request clarification or add additional context in comments.

Comments

1

Configuration.configure expects a 'class path' or 'resource' path (in your case starting from src). So if you remove '/First/src/mypackage' from your path, that should solve the file not found error.

And on the same note, you should also remove it from your reference to Employee.hbm.xml.

For further info, look at the docs for getResource in java.lang.Class (http://docs.oracle.com/javase/7/docs/api/index.html?java/lang/Class.html)

Comments