Thread: Hibernate error
View Single Post
  #5 (permalink)  
Old 06-04-2008, 06:03 AM
Bala123 Bala123 is offline
Member
 
Join Date: Jun 2008
Posts: 1
Bala123 is on a distinguished road
Hibernate error for bala123
Hi

I am new to Hibernate.
I am trying to insert tha data in Oracle9i database through Hibernate3.1 by using the MyEclipse6 IDE.

error is:
"Exception in thread "main" org.hibernate.MappingException: Unknown
entityrg.hiber.test.DepthomeId "

Could you please check it and send the solution.

hbm.cfg.xml file
-----------------------
<hibernate-configuration>

<session-factory name="sessionfactory">
<property name="connection.username">scott</property>
<property name="connection.url">
jdbcracle:thin:@localhost:1521:OraBala
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="myeclipse.connection.profile">
BalaHiber
</property>
<property name="connection.password">tiger</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>

<mapping resource="org/hiber/test/Depthome.hbm.xml" />

</session-factory>

</hibernate-configuration>
-----------------------------------------------------------------

depthome.hbm.xml file
------------------------
<hibernate-mapping>
<class name="org.hiber.test.Depthome" table="DEPTHOME" schema="SCOTT">
<composite-id name="id" class="org.hiber.test.DepthomeId">
<key-property name="dno" type="java.lang.Long">
<column name="DNO" precision="2" scale="0" />
</key-property>
<key-property name="dname" type="java.lang.String">
<column name="DNAME" length="10" />
</key-property>
<key-property name="loc" type="java.lang.String">
<column name="LOC" length="15" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
----------------------------------------------------------



POJO Class for DepthomeId class file
---------------------------------------

package org.hiber.test;

/**
* DepthomeId entity.
*
* @author MyEclipse Persistence Tools
*/

public class DepthomeId implements java.io.Serializable {

// Fields

private Long dno;
private String dname;
private String loc;

// Constructors

/** default constructor */
public DepthomeId() {
}

/** full constructor */
public DepthomeId(Long dno, String dname, String loc) {
this.dno = dno;
this.dname = dname;
this.loc = loc;
}

// Property accessors

public Long getDno() {
return this.dno;
}

public void setDno(Long dno) {
this.dno = dno;
}

public String getDname() {
return this.dname;
}

public void setDname(String dname) {
this.dname = dname;
}

public String getLoc() {
return this.loc;
}

public void setLoc(String loc) {
this.loc = loc;
}

public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof DepthomeId))
return false;
DepthomeId castOther = (DepthomeId) other;

return ((this.getDno() == castOther.getDno()) || (this.getDno() != null
&& castOther.getDno() != null && this.getDno().equals(
castOther.getDno())))
&& ((this.getDname() == castOther.getDname()) || (this
.getDname() != null
&& castOther.getDname() != null && this.getDname()
.equals(castOther.getDname())))
&& ((this.getLoc() == castOther.getLoc()) || (this.getLoc() != null
&& castOther.getLoc() != null && this.getLoc().equals(
castOther.getLoc())));
}

public int hashCode() {
int result = 17;

result = 37 * result
+ (getDno() == null ? 0 : this.getDno().hashCode());
result = 37 * result
+ (getDname() == null ? 0 : this.getDname().hashCode());
result = 37 * result
+ (getLoc() == null ? 0 : this.getLoc().hashCode());
return result;
}

}
-------------------------------------------------------------

Hibernate class of a Hibappone.java file
------------------------------------------->

package org.hiber.test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.*;
import org.hibernate.*;

public class HibAppOne {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

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

// Session session=org.hiber.test.OraSF.currentSession();
Transaction transaction=session.beginTransaction();
System.out.println("Up to transaction was created");

//Depthome depthome=new Depthome();
DepthomeId depthomeId=new DepthomeId();


depthomeId.setDno(new Long(1));
depthomeId.setDname("Bali");
depthomeId.setLoc("Vgya");

session.save(depthomeId);

transaction.commit();
session.close();


}

}

Let me know any solution for this.

Bala
Reply With Quote