hi guys, i am not sure what is the real problem, so i named the title such way, hope you guys can help me out.
Hibernate version: 3.1
Mapping documents:
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 Apr 13, 2006 11:26:50 PM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping auto-import="false">
<class name="gov.mohr.ems.e.ems.entity.RefActivityStatus" table="EMS_REF_ACTIVITY_STATUS" schema="EMS">
<id name="statusCode" type="string">
<column name="STATUS_CODE" length="1" />
<generator class="assigned" />
</id>
<property name="statusDescription" type="string">
<column name="STATUS_DESCRIPTION" length="20" not-null="true" />
</property>
<property name="statusDescriptionEn" type="string">
<column name="STATUS_DESCRIPTION_EN" length="20" not-null="true" />
</property>
<property name="lastUpdatedBy" type="string">
<column name="LAST_UPDATED_BY" length="20" not-null="true" />
</property>
<property name="lastUpdatedDate" type="date">
<column name="LAST_UPDATED_DATE" length="7" not-null="true" />
</property>
<property name="effectiveDate" type="date">
<column name="EFFECTIVE_DATE" length="7" not-null="true" />
</property>
<property name="inactiveDate" type="date">
<column name="INACTIVE_DATE" length="7" />
</property>
<set name="f13CancelLicenseHdrStatuses" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.f.f13.entity.CancelLicenseHdrStatus" />
</set>
<set name="KPp2s" inverse="true">
<key>
<column name="STATUS" length="1" />
</key>
<one-to-many class="gov.mohr.ems.k.entity.Pp2" />
</set>
<set name="f03EmployGeneralWkrStatuses" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.f.f03.entity.EmployGeneralWkrStatus" />
</set>
<set name="OComplaints" inverse="true">
<key>
<column name="STATUS" length="1" />
</key>
<one-to-many class="gov.mohr.ems.o.entity.Complaint" />
</set>
<set name="h01EmployerSiteVisits" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.h.h01.entity.EmployerSiteVisit" />
</set>
<set name="f12LicensePickupStatuses" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.f.f12.entity.LicensePickupStatus" />
</set>
<set name="j01CollectiveAgreements" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.j.j01.entity.CollectiveAgreement" />
</set>
<set name="c06VisitCriterias" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c06.entity.VisitCriteria" />
</set>
<set name="f02EmployMaidStatuses" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.f.f02.entity.EmployMaidStatus" />
</set>
<set name="c03IndustrialActions" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c03.entity.IndustrialAction" />
</set>
<set name="a07Summonses" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.a.a07.entity.Summons" />
</set>
<set name="f12LicenseHdrStatuses" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.f.f12.entity.LicenseHdrStatus" />
</set>
<set name="c01TradeDisputes" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c01.entity.TradeDispute" />
</set>
<set name="d08InspectionReports" inverse="true">
<key>
<column name="STATUS" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.d.d08.entity.InspectionReport" />
</set>
<set name="j02Variations" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.j.j02.entity.Variation" />
</set>
<set name="d02EmployerNers" inverse="true">
<key>
<column name="STATUS" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.d.d02.entity.EmployerNer" />
</set>
<set name="c02ClaimForRecognitions" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c02.entity.ClaimForRecognition" />
</set>
<set name="h01EmployerProfiles" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.h.h01.entity.EmployerProfile" />
</set>
<set name="f01RecommLetterStatuses" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.f.f01.entity.RecommLetterStatus" />
</set>
<set name="h01SpecialGrpProfiles" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.h.h01.entity.SpecialGrpProfile" />
</set>
<set name="c04ClaimForReinstatements" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c04.entity.ClaimForReinstatement" />
</set>
<set name="c08ReportForAffidavits" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c08.entity.ReportForAffidavit" />
</set>
<set name="c05Complaints" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c05.entity.Complaint" />
</set>
<set name="d01EmployerRegistrations" inverse="true">
<key>
<column name="STATUS" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.d.d01.entity.EmployerRegistration" />
</set>
<set name="a01Complaints" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.a.a01.entity.Complaint" />
</set>
<set name="MLicenseApplications" inverse="true">
<key>
<column name="STATUS" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.m.entity.LicenseApplication" />
</set>
<set name="h01SpecialGrpInterviews" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.h.h01.entity.SpecialGrpInterview" />
</set>
<set name="c07Scopes" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c07.entity.Scope" />
</set>
<set name="h01EmployerRequisitions" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.h.h01.entity.EmployerRequisition" />
</set>
<set name="c06Visits" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.c.c06.entity.Visit" />
</set>
<set name="BTradeUnions" inverse="true">
<key>
<column name="STATUS" length="1" />
</key>
<one-to-many class="gov.mohr.ems.b.entity.TradeUnion" />
</set>
<set name="KAccidentCases" inverse="true">
<key>
<column name="STATUS" length="1" />
</key>
<one-to-many class="gov.mohr.ems.k.entity.AccidentCase" />
</set>
<set name="a06LabourCases" inverse="true">
<key>
<column name="STATUS_CODE" length="1" />
</key>
<one-to-many class="gov.mohr.ems.a.a06.entity.LabourCase" />
</set>
<set name="f14CancelApHdrStatuses" inverse="true">
<key>
<column name="STATUS_CODE" length="1" not-null="true" />
</key>
<one-to-many class="gov.mohr.ems.f.f14.entity.CancelApHdrStatus" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():My code actually uses Spring-hibernate implementation and it is running during a JUnit test ant task as follows:
Code:
...
<!-- run junit -->
<target name="junit" depends="compile-all">
<mkdir dir="${build.junit.dir}"/>
<javac srcdir="${src.junit.dir}" destdir="${build.junit.dir}" debug="${javac.debug}">
<classpath>
<path refid="project.lib.classpath"/>
<path refid="project.build.classpath"/>
<fileset dir="${lib.dir}">
<include name="junit/*.jar"/>
<include name="jdbc/*.jar"/>
</fileset>
</classpath>
</javac>
<copy todir="${build.junit.dir}">
<fileset dir="${src.junit.dir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
<junit printsummary="true" fork="true" forkmode="once" maxmemory="512M">
<formatter type="plain"/>
<classpath>
<path refid="project.lib.classpath"/>
<path refid="project.build.classpath"/>
<pathelement path="${build.junit.dir}"/>
<fileset dir="${lib.dir}">
<include name="junit/*.jar"/>
<include name="jdbc/*.jar"/>
</fileset>
</classpath>
<batchtest todir="${build.junit.dir}">
<fileset dir="${src.junit.dir}">
<!--<include name="**/*Test.java"/>-->
<include name="**/DefaultQueryMethodTest.java"/>
</fileset>
</batchtest>
</junit>
</target>
...
The application context file of Spring:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</prop>
<prop key="hibernate.connection.url">jdbc:oracle:thin:@xxx.XXX.XXX.xxx:1521:EMSC</prop>
<!--prop key="hibernate.hbm2ddl.auto">create</prop-->
<prop key="hibernate.connection.username">hibernate</prop>
<prop key="hibernate.connection.password">hibernate</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
</props>
</property>
<property name="mappingLocations">
<value>classpath*:gov/mohr/**/*.hbm.xml</value>
</property>
</bean>
<bean id="gov.mohr.ems.core.entity.logic.DefaultQueryMethod" class="gov.mohr.ems.core.entity.logic.DefaultQueryMethod"/>
</beans>
The implementation of the file from test case:
Code:
...
public class DefaultQueryMethodTest
extends AbstractDependencyInjectionSpringContextTests {
private static final String[] CONFIG_LOCATIONS = new String[] {
"/applicationcontext.xml"
};
protected Log log = LogFactory.getLog(DefaultQueryMethodTest.class);
/**
* Returns the applicationcontext.xml locations
*/
protected String[] getConfigLocations() {
return CONFIG_LOCATIONS;
}
public void testSingleOperatorEqual() {
log.info("running DefaultQueryMethodTest.testSingleOperatorEqual()");
QueryMethod defaultQueryMethod = (DefaultQueryMethod) applicationContext.getBean(DefaultQueryMethod.class.getName());
QueryCriteria queryCriteria = new QueryCriteria();
Condition condition = new Condition();
condition.setProperty("statusCode");
condition.setOperator(Condition.OPERATOR_EQUAL);
condition.setValue("O");
List<Condition> conditionList = new ArrayList<Condition>();
conditionList.add(condition);
queryCriteria.setConditions(conditionList);
queryCriteria.setEntityName("RefActivityStatus");
List result = new ArrayList();
try {
result = defaultQueryMethod.executeQuery(queryCriteria);
} catch (IllegalAccessException e) {
log.error(e.getMessage());
e.printStackTrace();
} catch (NoSuchMethodException e) {
log.error(e.getMessage());
e.printStackTrace();
} catch (InvocationTargetException e) {
log.error(e.getMessage());
e.printStackTrace();
} finally {
if ((null != result) && (result.size() > 0)) {
log.info(result.size());
System.out.print((RefActivityStatus) result.get(0));
}
}
}
}
And this is the implementation of the logic of
DefaultQueryMethod.javaCode:
...
public class DefaultQueryMethod extends ImplSupport implements QueryMethod {
/** Construct apache common log method */
protected Log log = LogFactory.getLog(DefaultQueryMethod.class);
/* To store local match mode matching **/
private Map matchModeMap = new HashMap();
/** Creates a new instance of DefaultQueryMethod */
public DefaultQueryMethod() {
matchModeMap.put(Condition.MATCH_MODE_ANYWHERE, MatchMode.ANYWHERE);
matchModeMap.put(Condition.MATCH_MODE_END, MatchMode.END);
matchModeMap.put(Condition.MATCH_MODE_EXACT, MatchMode.EXACT);
matchModeMap.put(Condition.MATCH_MODE_START, MatchMode.START);
}
/**
* The proper implementation of execute query
*/
public List executeQuery(QueryCriteria queryCriteria)
throws IllegalAccessException, NoSuchMethodException,
InvocationTargetException {
log.info("executeQuery(QueryCriteria queryCriteria)");
Session sess = getSession();
Criteria criteria = sess.createCriteria(queryCriteria.getEntityName());
if (queryCriteria.getConditions().size() > 0) {
List criteriaList = queryCriteria.getConditions();
Iterator it = criteriaList.iterator();
while (it.hasNext()) {
Condition condition = (Condition) it.next();
if (null != condition.getValue()) {
if (condition.getOperator().equals(Condition.OPERATOR_ILIKE) &&
(null != condition.getMatchMode())) {
criteria.add(Restrictions.ilike(condition.getProperty(),
(String) condition.getValue(),
(MatchMode) matchModeMap.get(condition.getMatchMode())));
} else if (condition.getOperator()
.equals(Condition.OPERATOR_LIKE) &&
(null != condition.getMatchMode())) {
criteria.add(Restrictions.like(condition.getProperty(),
(String) condition.getValue(),
(MatchMode) matchModeMap.get(condition.getMatchMode())));
} else {
Method mtd = Restrictions.class.getMethod(condition.getOperator(),
new Class[] {
String.class,
Object.class
});
Criterion res = (Criterion) mtd.invoke(null,
new Object[] {
condition.getProperty(),
condition.getValue()
});
criteria.add(res);
}
}
}
}
return criteria.list();
}
}
Full stack trace of any exception that occurs:Code:
...
Running gov.mohr.ems.core.entity.logic.DefaultQueryMethodTest
2006-04-19 15:08:27,078 [INFO ] org.springframework.test.AbstractSpringContextTests.loadContextLocations(AbstractSpringContextTests.java:133) - Loading config for: /applicationcontext.xml
2006-04-19 15:08:27,140 [INFO ] org.springframework.core.CollectionFactory.<clinit>(CollectionFactory.java:66) - JDK 1.4+ collections available
2006-04-19 15:08:27,187 [INFO ] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:163) - Loading XML bean definitions from class path resource [applicationcontext.xml]
2006-04-19 15:08:27,437 [INFO ] org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:92) - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=8843841]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [sessionFactory,gov.mohr.ems.core.workflow.logic.Workflow,gov.mohr.ems.core.notification.logic.Notification,gov.mohr.ems.core.entity.logic.DefaultQueryMethod]; root of BeanFactory hierarchy
2006-04-19 15:08:27,437 [INFO ] org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:290) - 4 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=8843841]
2006-04-19 15:08:27,453 [INFO ] org.springframework.context.support.AbstractApplicationContext.initMessageSource(AbstractApplicationContext.java:432) - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@1430b5c]
2006-04-19 15:08:27,453 [INFO ] org.springframework.context.support.AbstractApplicationContext.initApplicationEventMulticaster(AbstractApplicationContext.java:454) - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@1e51060]
2006-04-19 15:08:27,468 [INFO ] org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:268) - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [sessionFactory,gov.mohr.ems.core.workflow.logic.Workflow,gov.mohr.ems.core.notification.logic.Notification,gov.mohr.ems.core.entity.logic.DefaultQueryMethod]; root of BeanFactory hierarchy]
2006-04-19 15:08:52,734 [INFO ] org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:749) - Building new Hibernate SessionFactory
2006-04-19 15:09:37,390 [INFO ] gov.mohr.ems.core.entity.logic.DefaultQueryMethodTest.testSingleOperatorEqual(DefaultQueryMethodTest.java:42) - running DefaultQueryMethodTest.testSingleOperatorEqual()
2006-04-19 15:09:37,390 [INFO ] gov.mohr.ems.core.entity.logic.DefaultQueryMethod.executeQuery(DefaultQueryMethod.java:56) - executeQuery(QueryCriteria queryCriteria)
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 70.469 sec
Test gov.mohr.ems.core.entity.logic.DefaultQueryMethodTest FAILED
Name and version of the database you are using: Oracle 10.2.1
The generated SQL (show_sql=true): N/A
Debug level Hibernate log excerpt:These are the log from apache logging:
Code:
Testsuite: gov.mohr.ems.core.entity.logic.DefaultQueryMethodTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 70.469 sec
Testcase: testSingleOperatorEqual took 70.453 sec
Caused an ERROR
Unknown entity: RefActivityStatus
org.hibernate.MappingException: Unknown entity: RefActivityStatus
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
at org.hibernate.impl.SessionImpl.getOuterJoinLoadable(SessionImpl.java:1548)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1514)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at gov.mohr.ems.core.entity.logic.DefaultQueryMethod.executeQuery(DefaultQueryMethod.java:97)
at gov.mohr.ems.core.entity.logic.DefaultQueryMethodTest.testSingleOperatorEqual(DefaultQueryMethodTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
What is wrong?