I'm working with eclipse and mysql. When I try to use some tables which has relationship, the above exception will be occurred(Unable to instantiate default tuplizer).
My library files are:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="cfg"/>
<classpathentry exported="true" kind="lib" path="lib/antlr-2.7.6.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-collections-3.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-lang-2.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/dom4j-1.6.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/flex-rds-server.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hibernate3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/javassist-3.9.0.GA.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jta-1.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry exported="true" kind="lib" path="lib/mysql-connector-java-5.1.10-bin.jar"/>
<classpathentry exported="true" kind="lib" path="lib/slf4j-api-1.5.10.jar"/>
<classpathentry exported="true" kind="lib" path="lib/slf4j-log4j12-1.5.10.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
My hibernate mapping files are:
Code:
<?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 name="mySessionFactory">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/elearner</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<!-- Hibernate session -->
<property name="current_session_context_class">thread</property>
<!-- Write SQL to log or console -->
<property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="Login.hbm.xml" />
<mapping resource="Users.hbm.xml" />
<mapping resource="DetExamsQuestions.hbm.xml" />
<mapping resource="DetAnswers.hbm.xml" />
<mapping resource="DetExams.hbm.xml" />
<mapping resource="McqExams.hbm.xml" />
<mapping resource="McqExamsQuestions.hbm.xml" />
<mapping resource="McqAnswers.hbm.xml" />
<mapping resource="StudyMaterial.hbm.xml" />
</session-factory>
</hibernate-configuration>
Mapping Files:
Code:
<?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 27 Feb, 2010 10:47:20 PM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="Users" table="users" catalog="elearner">
<id name="userId" type="string">
<column name="User_Id" length="45" />
<generator class="foriegn">
<param name="property">login</param>
</generator>
</id>
<one-to-one name="login" class="Login" constrained="true"></one-to-one>
<property name="firstName" type="string">
<column name="First_Name" length="45" not-null="true" />
</property>
<property name="midName" type="string">
<column name="Mid_Name" length="45" />
</property>
<property name="lastName" type="string">
<column name="Last_Name" length="45" not-null="true" />
</property>
<property name="dateOfBirth" type="string">
<column name="Date_Of_Birth" length="45" />
</property>
<property name="gender" type="string">
<column name="Gender" length="45" />
</property>
<property name="civilStatus" type="string">
<column name="Civil_Status" length="45" />
</property>
<property name="address1" type="string">
<column name="Address1" length="100" />
</property>
<property name="address2" type="string">
<column name="Address2" length="100" />
</property>
<property name="city" type="string">
<column name="City" length="100" />
</property>
<property name="state" type="string">
<column name="State" length="100" />
</property>
<property name="country" type="string">
<column name="Country" length="45" />
</property>
<property name="tpNo" type="string">
<column name="TP_No" length="15" />
</property>
<property name="mobNo" type="string">
<column name="Mob_No" length="15" />
</property>
<property name="email" type="string">
<column name="Email" length="100" />
</property>
<property name="dateOfJoin" type="string">
<column name="Date_Of_Join" length="45" />
</property>
<property name="dateOfResign" type="string">
<column name="Date_Of_Resign" length="45" />
</property>
</class>
</hibernate-mapping>
Code:
<?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 27 Feb, 2010 10:47:20 PM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="Login" table="login" catalog="elearner">
<id name="userId" type="string">
<column name="User_Id" length="45" />
<generator class="assigned" />
</id>
<property name="password" type="string">
<column name="Password" length="45" />
</property>
<property name="userRole" type="string">
<column name="User_Role" length="45" not-null="true" />
</property>
<one-to-one name="users" class="Users"></one-to-one>
</class>
</hibernate-mapping>
and Session Factory file:
Code:
package com.anbu.manager;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions;
import org.apache.commons.lang.StringUtils;
import com.anbu.getset.*;
/**
* @author Anbu
*
*/
@SuppressWarnings("unused")
public class ElearnerImpl {
@SuppressWarnings("unchecked")
public List<Users> getUserListImpl(String sUser,String sPassword)
{
List<Users> allUsers = null;
try {
//Set up Hibernate Session
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
Transaction tx = session.beginTransaction();
if (StringUtils.isBlank(sUser))
{
allUsers = session.createCriteria(Users.class).list();
}
else
{
// Use Property not column names
allUsers = session.createCriteria(Users.class).add(Restrictions.eq("loginName",sUser))
.add(Restrictions.eq("loginPassword", sPassword)).list();
}
}
catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return allUsers;
}
public void addLogin(String userId, String password ,String userRole)
{
Configuration configuration = new Configuration();
SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
transaction.begin();
Login l1 = new Login();
l1.setUserId(userId);
l1.setPassword(password);
l1.setUserRole(userRole);
session.save(l1);
transaction.commit();
session.close();
}
@SuppressWarnings("unchecked")
public List<StudyMaterial> getStudyMaterialList(String courseModuleNo)
{
List<StudyMaterial> allStudy = null;
try {
//Set up Hibernate Session
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
Transaction tx = session.beginTransaction();
if (StringUtils.isBlank(courseModuleNo))
{
allStudy = session.createCriteria(StudyMaterial.class).list();
}
else
{
// Use Property not column names
allStudy = session.createCriteria(StudyMaterial.class).add(Restrictions.eq("courseModuleNo",courseModuleNo)).list();
}
}
catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return allStudy;
}
when I run a test file to retrieve data I'm getting error as below:
Code:
org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:101)
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructDefaultTuplizer(ComponentTuplizerFactory.java:122)
at org.hibernate.tuple.component.ComponentEntityModeToTuplizerMapping.<init>(ComponentEntityModeToTuplizerMapping.java:75)
at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:73)
at org.hibernate.mapping.Component.buildType(Component.java:175)
at org.hibernate.mapping.Component.getType(Component.java:168)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)
at org.hibernate.mapping.RootClass.validate(RootClass.java:216)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1149)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1334)
at com.anbu.manager.ElearnerImpl.getStudyMaterialList(ElearnerImpl.java:89)
at com.anbu.manager.TestUsers.main(TestUsers.java:33)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:98)
... 11 more
Caused by: org.hibernate.MappingException: component class not found: DetExamsQuestionsId
at org.hibernate.mapping.Component.getComponentClass(Component.java:127)
at org.hibernate.tuple.component.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:156)
at org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:66)
at org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:61)
... 16 more
Caused by: java.lang.ClassNotFoundException: DetExamsQuestionsId
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.mapping.Component.getComponentClass(Component.java:124)
... 19 more
Exception in thread "main" java.lang.NullPointerException
at com.anbu.manager.TestUsers.main(TestUsers.java:35)
Can anybody please help me this problem as I new to hibernate and this is my first project which I'm doing for my college project..