A
Amit Jain
Hi
I'm starting to learn hibernate. I found a problem in my code. I have
made the database table in MYSQL with name "userinfo" and I also made
a mapping file. But I am getting "null" while calling function
"getHibernateTemplate()":
This is the code to show the list:
============ MemberDAOImpl.java Start =========
package com.mycomp.crtracker.dao;
public class MemberDAOImpl extends HibernateDaoSupport implements
DataAccessObject{
public ValueObject findByPK(String primaryKey) throws
DataAccessException {
***
**
List myList = getHibernateTemplate().find("from MemberVO
membervo where membervo.memberid=75571");
***
**
}
}
============ MemberDAOImpl.java END =========
============ hibernate.cfg.xml Start ===========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/
hibernate-
configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</
property>
<property
name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</
property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:
3306/crtracker</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</
property>
<mapping resource="com/mycomp/crtracker/vo/h_mapping/
userinfo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
============ hibernate.cfg.xml END ===========
============ userinfo.hbm.xml Start===========
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
DTD
3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 3, 2009 5:28:33 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="com.mycomp.crtracker.vo.MemberVO" table="userinfo"
catalog="crtracker">
<id name="userId" type="string">
<column name="USERID" length="15" />
<generator class="assigned" />
</id>
<property name="firstName" type="string">
<column name="FIRSTNAME" length="15" />
</property>
<property name="lastName" type="string">
<column name="LASTNAME" length="15" />
</property>
<property name="email" type="string">
<column name="EMAIL" length="15" />
</property>
<property name="password" type="string">
<column name="PASSWORD" length="15" />
</property>
<property name="memberId" type="java.lang.Integer">
<column name="MEMBERID" unique="true" />
</property>
</class>
</hibernate-mapping>
============ userinfo.hbm.xml END===========
============ hibernate.reveng.xml Start===========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/
Hibernate
Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/
hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog="crtracker"/>
<table-filter match-name="userinfo"/>
</hibernate-reverse-engineering>
============ hibernate.reveng.xml END===========
============ MemberVO.java Start =========
package com.mycomp.crtracker.vo;
public class MemberVO extends ValueObject implements Serializable{
private String memberId;
private String firstName;
private String lastName;
private String userId;
private String password;
private String email;
/*setters and getters for all above listed*/
}
============ MemberVO.java End =========
I'm starting to learn hibernate. I found a problem in my code. I have
made the database table in MYSQL with name "userinfo" and I also made
a mapping file. But I am getting "null" while calling function
"getHibernateTemplate()":
This is the code to show the list:
============ MemberDAOImpl.java Start =========
package com.mycomp.crtracker.dao;
public class MemberDAOImpl extends HibernateDaoSupport implements
DataAccessObject{
public ValueObject findByPK(String primaryKey) throws
DataAccessException {
***
**
List myList = getHibernateTemplate().find("from MemberVO
membervo where membervo.memberid=75571");
***
**
}
}
============ MemberDAOImpl.java END =========
============ hibernate.cfg.xml Start ===========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate
Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/
hibernate-
configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</
property>
<property
name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</
property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:
3306/crtracker</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</
property>
<mapping resource="com/mycomp/crtracker/vo/h_mapping/
userinfo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
============ hibernate.cfg.xml END ===========
============ userinfo.hbm.xml Start===========
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
DTD
3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 3, 2009 5:28:33 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="com.mycomp.crtracker.vo.MemberVO" table="userinfo"
catalog="crtracker">
<id name="userId" type="string">
<column name="USERID" length="15" />
<generator class="assigned" />
</id>
<property name="firstName" type="string">
<column name="FIRSTNAME" length="15" />
</property>
<property name="lastName" type="string">
<column name="LASTNAME" length="15" />
</property>
<property name="email" type="string">
<column name="EMAIL" length="15" />
</property>
<property name="password" type="string">
<column name="PASSWORD" length="15" />
</property>
<property name="memberId" type="java.lang.Integer">
<column name="MEMBERID" unique="true" />
</property>
</class>
</hibernate-mapping>
============ userinfo.hbm.xml END===========
============ hibernate.reveng.xml Start===========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/
Hibernate
Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/
hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog="crtracker"/>
<table-filter match-name="userinfo"/>
</hibernate-reverse-engineering>
============ hibernate.reveng.xml END===========
============ MemberVO.java Start =========
package com.mycomp.crtracker.vo;
public class MemberVO extends ValueObject implements Serializable{
private String memberId;
private String firstName;
private String lastName;
private String userId;
private String password;
private String email;
/*setters and getters for all above listed*/
}
============ MemberVO.java End =========