• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

org.hibernate.MappingException: Unknown entity:

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my dao interface

/*
* Created on 07-Oct-2006
*
*/
package roseindia.dao;

import java.sql.SQLException;
import java.util.Collection;
import roseindia.dao.hibernate.*;

import org.springframework.dao.DataAccessException;


/**
* @author Deepak Kumar
*
*/
public interface SpringHibernateDAO {

/**
* Update Article object ot the datastore.
*
*/
public void updateUser(roseindia.dao.hibernate.Login obj) throws DataAccessException;


/**
* Retrieve <code>Article</code> from the datastore.
* @return Article.
*/
public roseindia.dao.hibernate.Login loadUser(String id) throws DataAccessException;


public TopicList loadTopic() throws DataAccessException,SQLException;

/**
* Retrieve all <code>true</code>/<code>false</code> from the datastore.
* @return a <code>true</code> or <code>fasel</code>.
*/
public boolean checkValidUserName(String strUserid) throws DataAccessException,java.sql.SQLException;

......................................
......................................
......................................

}


here is my Implementation class

/*
* Created on Aug 5, 2005
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package roseindia.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import roseindia.dao.hibernate.Login;
import roseindia.dao.hibernate.TopicList;
import roseindia.web.common.UsersList;


/**
* Hibernate implementation of the JobModule interface.
*
*


* The mappings are defined in "roseindia.hbm.xml", located in the root of the
* classpath.
*
* @author Deepak Kumar
* @since 07-Oct-2006
*/
public class SpringHibernateDAOImpl extends HibernateDaoSupport implements
SpringHibernateDAO {


//check admin login

public boolean checkUserLogin(String strUserName, String strPassword) throws DataAccessException,java.sql.SQLException{
boolean valid = false;
System.out.println("inside checkUserLogin method");
Connection conn = this.getSession().connection();
//Write jdbc code to validate the user against database
Statement smt = conn.createStatement();
ResultSet rs;
//write select query for checking password

String query="select id from login where loginid='"+strUserName+"' and password='"+strPassword+"'";
rs=smt.executeQuery(query);

if(rs.next()== true){
valid=true;

}else{
valid=false;
}

smt.close();
rs.close();
conn.close();

return valid;


}


public void addUser(roseindia.dao.hibernate.Login obj) throws DataAccessException{
System.out.println("inside addUser method");
getHibernateTemplate().save(obj);
}

public void updateUser(roseindia.dao.hibernate.Login obj) throws DataAccessException{
System.out.println("inside updateUser method");
getHibernateTemplate().update(obj);
}


public roseindia.dao.hibernate.Login loadUser(String id) throws DataAccessException{
System.out.println("inside loadUser method");
//return getHibernateTemplate().find("from roseindialocal.dao.hibernate.Article obj where obj.id = '" + id + "'");
return (roseindia.dao.hibernate.Login) getHibernateTemplate().get(Login.class,new Integer(id));
}

public roseindia.dao.hibernate.TopicList loadTopic() throws DataAccessException,SQLException{
System.out.println("inside loadTopic method");

return (roseindia.dao.hibernate.TopicList) getHibernateTemplate().get(TopicList.class, new Long(0));
}

public boolean checkValidUserName(String strUserid) throws DataAccessException,java.sql.SQLException{
boolean valid = false;
Connection conn = this.getSession().connection();
//Write jdbc code to validate the user against database
Statement smt = conn.createStatement();
ResultSet rs;
//write select query for checking password

String query="select id from login where loginid='"+strUserid+"'";
rs=smt.executeQuery(query);


if(rs.next() == true){

valid=true;

}else{
valid=false;
}

smt.close();
rs.close();
conn.close();


return valid;
}

// get Topic List added by naresh

public Collection getTopicList()throws DataAccessException,java.sql.SQLException{
Connection conn = this.getSession().connection();
Statement smt = conn.createStatement();
ResultSet rs=null;
ArrayList topicList = new ArrayList();
String listQuery="SELECT TOPIC_ID, TOPIC_NAME FROM TOPIC";
rs = smt.executeQuery(listQuery);
//Write jdbc code to validate the user against database
while (rs.next()){
TopicList tlist = new TopicList();
long topic_id = rs.getLong("TOPIC_ID");
tlist.setTid(topic_id);
String topic_name = rs.getString("TOPIC_NAME");
tlist.setTname(topic_name);
topicList.add(tlist);
}


return topicList;
}

/*
*
*public List getTopicList()throws DataAccessException,java.sql.SQLException{
DataSource ds =
Connection conn = this.getSession().connection();
Statement smt = conn.createStatement();
ResultSet rs=null;
ArrayList topicList = new ArrayList();
String listQuery="SELECT TOPIC_ID, TOPIC_NAME FROM TOPIC";
rs = smt.executeQuery(listQuery);
//Write jdbc code to validate the user against database
while (rs.next()){
TopicList tlist = new TopicList();
long topic_id = rs.getLong("TOPIC_ID");
tlist.setTid(topic_id);
String topic_name = rs.getString("TOPIC_NAME");
tlist.setTname(topic_name);
topicList.add(tlist);
}


return topicList;
}

*/


//get latest jobs
public Collection getUsersList()throws DataAccessException,java.sql.SQLException{



Connection conn = this.getSession().connection();

//Write jdbc code
Statement smt = conn.createStatement();

ResultSet rs=null;

ArrayList list = new ArrayList();

String query="SELECT id,loginid positionVacant FROM login";



rs=smt.executeQuery(query);



while(rs.next()){

UsersList userslist =new UsersList();

int jobid=rs.getInt("id");
userslist.setId(jobid);

String loginid=rs.getString("loginid");
userslist.setLoginid(loginid);

list.add(userslist);

}

rs.close();
smt.close();
conn.close();


return list;
}

public int getUserId(String strUserid) throws DataAccessException,java.sql.SQLException{

Connection conn = this.getSession().connection();
//Write jdbc code to validate the user against database
Statement smt = conn.createStatement();
ResultSet rs;
//write select query for checking password

String query="select id from login where loginid='"+strUserid+"'";
rs=smt.executeQuery(query);
rs.next();

int id=rs.getInt("id");


smt.close();
rs.close();
conn.close();
return id;
}

// retrive user forget password
public String[] retriveUserForgetPassword(String strUserName, String strEmail) throws DataAccessException,java.sql.SQLException{
//boolean valid = false;




Connection conn = this.getSession().connection();
//Write jdbc code to validate the user against database
Statement smt = conn.createStatement();

ResultSet rs;
String query;


//write select query for checking password

if(strUserName != ""){

query="select password,email,loginid from login where loginid='"+strUserName+"'";

}else{
query="select password,email,loginid from login where email='"+strEmail+"'";
}

rs=smt.executeQuery(query);



String[] returnValues = new String[3];



while(rs.next()){



returnValues[0]=rs.getString("password");

returnValues[1]=rs.getString("email");

returnValues[2]=rs.getString("loginid");


}

smt.close();
rs.close();
conn.close();

if(returnValues[0] != null){

return returnValues;

} else{
String[] errorValues = new String[2];
errorValues[0]="error";
return errorValues;
}
}

//


}




I am getting below error .......................



org.hibernate.MappingException: Unknown entity: roseindia.dao.hibernate.TopicList
org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:513)
org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:66)
org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:889)
org.hibernate.impl.SessionImpl.get(SessionImpl.java:826)
org.hibernate.impl.SessionImpl.get(SessionImpl.java:819)
org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:451)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:445)
org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:439)
roseindia.dao.SpringHibernateDAOImpl.loadTopic(SpringHibernateDAOImpl.java:89)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
$Proxy8.loadTopic(Unknown Source)
roseindia.web.struts.action.TopicListAction.execute(TopicListAction.java:39)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The comments in the code mention using "roseindia.hbm.xml" to define the mappings... does that file contain a mapping of the roseindia.dao.hibernate.TopicList class?

Is this happening only with TopicList or with other classes? If it happens with all your classes it would probably be because the mapping file isn't done correctly, or the code can't find it.
 
abheeshek reddy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nathan Pruett wrote:The comments in the code mention using "roseindia.hbm.xml" to define the mappings... does that file contain a mapping of the roseindia.dao.hibernate.TopicList class?

Is this happening only with TopicList or with other classes? If it happens with all your classes it would probably be because the mapping file isn't done correctly, or the code can't find it.





Thanks for reply.
I forgot to remove the comments, i am not using that file. i am using different mapping files for different modules like


For login login.hbm.xml
for TopicList TopicList.hbm.xml

here i am posting my pojo class and mapping file

package roseindia.dao.hibernate;

public class TopicList {
private long tid;
private String tname;

public void TopList(long tid, String tname){
this.tid = tid;
this.tname = tname;
System.out.println("inside TopList ---- >");

}
public long getTid() {
System.out.println("inside TopList bean and the vaule of topic id :"+tid);
return tid;
}
public void setTid(long tid) {
this.tid = tid;
}
public String getTname() {
System.out.println("inside TopList bean and the vaule of topic name :"+tname);
return tname;
}
public void setTname(String tname) {
this.tname = tname;
}
}

mapping file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="true" default-lazy="false">

<class name="TopicList" table="Topic">

<id name="tid" type="long" column="TOPIC_ID">
<generator class="increment"/>
</id>

<property name="tname" type="java.lang.String" column="TOPIC_NAME"/>


</class>
</hibernate-mapping>

The error is happening with only TopicList
all other class are working fine...

do i need to set any classpath
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<class name="TopicList" table="Topic">



I think this is your problem - the full classname (with the package) must be specified.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the more appropriate ORM forum where Hibernate questions are asked.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic