* 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)
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
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.
<class name="TopicList" table="Topic">
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |