掲示板
org.hibernate.MappingException: Unknown entity when implementing finder
7年前 に Nha Trinh によって更新されました。
org.hibernate.MappingException: Unknown entity when implementing finder
New Member 投稿: 1 参加年月日: 16/12/21 最新の投稿
Hello Everyone,
I followed to this tutorial: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/dynamic-query
to create my custom finder by using dynamic query.
This is the finder method in my implementation finder: ProcessFinderImpl.java
I want to use this finder through *LocalServiceUtil, so I created a method in *LocalServiceImpl.
This is the method in my local implementation service: ProcessLocalServiceImpl.java:
Problem number 1 is Service Builder didn't generate the *FinderUtil (ProcessFinderUtil).
So in my local implementation service, instead of using ProcessFinderUtil.findByDiseaseId(diseaseId), I have to use getProcessFinder() from ProcessLocalServiceBaseImpl to get the finder and call findByDiseaseId(diseaseId).
Problem number 2 is this exception: org.hibernate.MappingException: Unknown entity
I am using Liferay 7.0 CE GA3.
Here is the module-hbm.xml:
Someone know what is my problem, please help.
Thanks in advance,
Nha.
I followed to this tutorial: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/dynamic-query
to create my custom finder by using dynamic query.
This is the finder method in my implementation finder: ProcessFinderImpl.java
public List<process> findByDiseaseId(int diseaseId) {
Session session = null;
try {
session = openSession();
DynamicQuery diseaseProcessQuery = DynamicQueryFactoryUtil.forClass(DiseaseProcess.class);
diseaseProcessQuery.add(RestrictionsFactoryUtil.eq("diseaseId", diseaseId))
.setProjection(ProjectionFactoryUtil.property("processId"));
DynamicQuery processQuery = DynamicQueryFactoryUtil.forClass(Process.class);
processQuery.add(PropertyFactoryUtil.forName("processId").in(diseaseProcessQuery));
List<process> processes = ProcessLocalServiceUtil.dynamicQuery(processQuery);
return processes;
} catch (Exception e) {
try {
throw new SystemException(e);
} catch (SystemException se) {
se.printStackTrace();
}
} finally {
closeSession(session);
}
return null;
}</process></process>
I want to use this finder through *LocalServiceUtil, so I created a method in *LocalServiceImpl.
This is the method in my local implementation service: ProcessLocalServiceImpl.java:
public List<process> findByDiseaseId(int diseaseId) {
ProcessFinder processFinder = getProcessFinder();
return processFinder.findByDiseaseId(diseaseId);
}</process>
Problem number 1 is Service Builder didn't generate the *FinderUtil (ProcessFinderUtil).
So in my local implementation service, instead of using ProcessFinderUtil.findByDiseaseId(diseaseId), I have to use getProcessFinder() from ProcessLocalServiceBaseImpl to get the finder and call findByDiseaseId(diseaseId).
Problem number 2 is this exception: org.hibernate.MappingException: Unknown entity
I am using Liferay 7.0 CE GA3.
Here is the module-hbm.xml:
<!--?xml version="1.0"?-->
<hibernate-mapping auto-import="false" default-lazy="false">
<import class="vn.nice.model.Disease" />
<import class="vn.nice.model.DiseaseProcess" />
<import class="vn.nice.model.Process" />
<class name="vn.nice.model.impl.DiseaseImpl" table="disease">
<id column="disease_id" name="diseaseId" type="int">
<generator class="increment" />
</id>
<property column="disease_code" name="diseaseCode" type="com.liferay.portal.dao.orm.hibernate.StringType" />
<property column="disease_label" name="diseaseLabel" type="com.liferay.portal.dao.orm.hibernate.StringType" />
<property column="disease_image" name="diseaseImage" type="com.liferay.portal.dao.orm.hibernate.StringType" />
</class>
<class name="vn.nice.model.impl.DiseaseProcessImpl" table="disease_process">
<id column="disease_process_id" name="diseaseProcessId" type="int">
<generator class="increment" />
</id>
<property column="disease_id" name="diseaseId" type="com.liferay.portal.dao.orm.hibernate.IntegerType" />
<property column="disease_process_sort" name="diseaseProcessSort" type="com.liferay.portal.dao.orm.hibernate.IntegerType" />
<property column="process_id" name="processId" type="com.liferay.portal.dao.orm.hibernate.IntegerType" />
</class>
<class name="vn.nice.model.impl.ProcessImpl" table="process">
<id column="process_id" name="processId" type="int">
<generator class="increment" />
</id>
<property column="process_code" name="processCode" type="com.liferay.portal.dao.orm.hibernate.StringType" />
<property column="process_label" name="processLabel" type="com.liferay.portal.dao.orm.hibernate.StringType" />
</class>
</hibernate-mapping>
Someone know what is my problem, please help.
Thanks in advance,
Nha.
6年前 に Victor Zorin によって更新されました。
RE: org.hibernate.MappingException: Unknown entity when implementing finder
Liferay Legend 投稿: 1228 参加年月日: 08/04/14 最新の投稿
Re: Problem number 2 is this exception: org.hibernate.MappingException: Unknown entity
There is an answer to the second problem. Try the following approach:
DynamicQueryFactoryUtil class has 2 methods forClass():
1. just taking the classname
2. taking the classname but you can also pass the ClassLoader
So, if you receive an "Unknown Entity" exception, put as a second argument your local class loader, e.g.
DynamicQuery diseaseProcessQuery = DynamicQueryFactoryUtil.forClass(DiseaseProcess.class, ProcessFinderImpl.class..getClassLoader() );
The 2nd argument will ensure that DynamicQueryFactoryUtil will use your package.
Worked for us.
There is an answer to the second problem. Try the following approach:
DynamicQueryFactoryUtil class has 2 methods forClass():
1. just taking the classname
2. taking the classname but you can also pass the ClassLoader
So, if you receive an "Unknown Entity" exception, put as a second argument your local class loader, e.g.
DynamicQuery diseaseProcessQuery = DynamicQueryFactoryUtil.forClass(DiseaseProcess.class, ProcessFinderImpl.class..getClassLoader() );
The 2nd argument will ensure that DynamicQueryFactoryUtil will use your package.
Worked for us.