Liferay JSF服务构建器配置错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Liferay JSF服务构建器配置错误相关的知识,希望对你有一定的参考价值。

是Liferay的新手。我创建了一个JSF portlet并向其添加了服务构建器。使用此链接Generate a Persistence Framework。配置服务构建器后,我使用服务构建器生成了源。但是在构建项目服务时遇到异常。

 Exception in thread "main" java.lang.IllegalArgumentException: No entity column exist with column database name guestbookId for entity Guestbook
 [echo]     at com.liferay.portal.tools.service.builder.ServiceBuilder._getEntityColumnByColumnDBName(ServiceBuilder.java:4242)
 [echo]     at com.liferay.portal.tools.service.builder.ServiceBuilder._getColumnLengths(ServiceBuilder.java:3857)
 [echo]     at com.liferay.portal.tools.service.builder.ServiceBuilder._createSQLIndexes(ServiceBuilder.java:3355)
 [echo]     at com.liferay.portal.tools.service.builder.ServiceBuilder.<init>(ServiceBuilder.java:796)
 [echo]     at com.liferay.portal.tools.service.builder.ServiceBuilder.main(ServiceBuilder.java:216)
 [echo]     -Dservice.tpl.spring_xml_session=com/liferay/portal/tools/service/builder/dependencies/spring_xml_session.ftl
 [echo] Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
[mkdir] Created dir: D:liferayliferay-plugins-sdk-7.0portletsjsfguestbook-portletdocrootWEB-INFservice-classes
 [copy] Copied 9 empty directories to 9 empty directories under D:liferayliferay-plugins-sdk-7.0portletsjsfguestbook-portletdocrootWEB-INFservice-classes
[javac] Compiling 38 source files to D:liferayliferay-plugins-sdk-7.0portletsjsfguestbook-portletdocrootWEB-INFservice-classes
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
  [jar] Building jar: D:liferayliferay-plugins-sdk-7.0portletsjsfguestbook-portletdocrootWEB-INFlibjsfguestbook-portlet-service.jar
[delete] Deleting directory D:liferayliferay-plugins-sdk-7.0portletsjsfguestbook-portletdocrootWEB-INFservice-classes
BUILD SUCCESSFUL
Total time: 8 seconds

在构建服务后,我已按照文章添加了代码。我没有配置以下代码的方法。

public Guestbook getFirstGuestbookByName(long groupId, String name) throws SystemException {
    Guestbook guestbook = null;

    List<Guestbook> guestbooks = guestbookPersistence.findByName(groupId, name); // This method is not exist.
    if (guestbooks != null && guestbooks.size() > 0) {
        guestbook = guestbooks.get(0);
    }

    return guestbook;
}

我的service.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd">
<service-builder package-path="com.liferay.docs.guestbook">
<author>muthuvignesh.k</author>
<namespace>GB</namespace>
<entity name="Guestbook" local-service="true" uuid="true">

    <!-- PK fields -->

    <column name="guestbookId" type="long" primary="true"></column>

    <!-- Group instance -->

    <column name="groupId" type="long"></column>

    <!-- Audit fields -->

    <column name="companyId" type="long"></column>
    <column name="userId" type="long"></column>
    <column name="userName" type="String"></column>
    <column name="createDate" type="Date"></column>
    <column name="modifiedDate" type="Date"></column>
    <column name="name" type="String"></column>
    <finder name="GroupId" return-type="Collection">
        <finder-column name="groupId"></finder-column>
    </finder>
</entity>
<entity name="Entry" local-service="true" uuid="true">

    <!-- PK fields -->

    <column name="entryId" type="long" primary="true"></column>

    <!-- Group instance -->

    <column name="groupId" type="long"></column>

    <!-- Audit fields -->

    <column name="companyId" type="long"></column>
    <column name="userId" type="long"></column>
    <column name="userName" type="String"></column>
    <column name="createDate" type="Date"></column>
    <column name="modifiedDate" type="Date"></column>
    <column name="name" type="String"></column>
    <column name="email" type="String"></column>
    <column name="message" type="String"></column>
    <column name="guestbookId" type="long"></column>
    <finder name="G_G" return-type="Collection">
        <finder-column name="groupId"></finder-column>
        <finder-column name="guestbookId"></finder-column>
    </finder>
</entity>
<exceptions>
    <exception>GuestbookName</exception>
    <exception>EntryName</exception>
    <exception>EntryMessage</exception>
    <exception>EntryEmail</exception>
</exceptions>

因为我已经使用了Liferay 7.0。如何克服这一点。

答案

Service Builder

问题似乎出现在您的服务构建器中。

1.最突出的是你的格式错误的XML。你需要关闭标签。 2.其次,在您的Java代码中,您尝试访问不存在的查找程序。您在hibernate文件中定义的唯一查找器是groupId。它看起来像

     return guestbookPersistence.findByGroupId(groupId);

3.要创建一个groupid和名称,发现它看起来与你的条目查找器类似。

    <finder name="G_N" return-type="Collection">
        <finder-column name="groupId"></finder-column>
        <finder-column name="name"></finder-column>
    </finder>

和你的java代码

return guestbookPersistence.findByG_N(groupId, name);

servitse.hml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd">
<service-builder package-path="com.latham.data">
    <author>muthuvignesh.k</author>
    <namespace>GB</namespace>
    <entity name="Guestbook" local-service="true" uuid="true">

        <!-- PK fields -->

        <column name="guestbookId" type="long" primary="true"></column>

        <!-- Group instance -->

        <column name="groupId" type="long"></column>

        <!-- Audit fields -->

        <column name="companyId" type="long"></column>
        <column name="userId" type="long"></column>
        <column name="userName" type="String"></column>
        <column name="createDate" type="Date"></column>
        <column name="modifiedDate" type="Date"></column>
        <column name="name" type="String"></column>
        <finder name="GroupId" return-type="Collection">
            <finder-column name="groupId"></finder-column>
        </finder>
        <finder name="G_N" return-type="Collection">
            <finder-column name="groupId"></finder-column>
            <finder-column name="name"></finder-column>
        </finder>
    </entity>

    <entity name="Entry" local-service="true" uuid="true">

        <!-- PK fields -->

        <column name="entryId" type="long" primary="true"></column>

        <!-- Group instance -->

        <column name="groupId" type="long"></column>

        <!-- Audit fields -->

        <column name="companyId" type="long"></column>
        <column name="userId" type="long"></column>
        <column name="userName" type="String"></column>
        <column name="createDate" type="Date"></column>
        <column name="modifiedDate" type="Date"></column>
        <column name="name" type="String"></column>
        <column name="email" type="String"></column>
        <column name="message" type="String"></column>
        <column name="guestbookId" type="long"></column>
        <finder name="G_G" return-type="Collection">
            <finder-column name="groupId"></finder-column>
            <finder-column name="guestbookId"></finder-column>
        </finder>
    </entity>
    <exceptions>
        <exception>GuestbookName</exception>
        <exception>EntryName</exception>
        <exception>EntryMessage</exception>
        <exception>EntryEmail</exception>
    </exceptions>
</service-builder>

您链接的教程适用于Liferay 6.2,但您的文档定义适用于Liferay 7.在6.2和7之间有一些非常大的变化。您的代码似乎与两者兼容,但您仍应牢记这一点。

另一答案

我在6.2中遇到了同样的错误。似乎错误发生在WEB-INF / sql / indexes.sql文件中。索引条目使用服务构建器无法找到的字段(但存在于service.xml中)。

我认为(但我无法验证)问题是由旧版本的liferay maven插件(6.2.0-ga1)引起的。通过删除文件并升级到6.2.5版,服务构建器生成了不同的index.sql并且构建成功。

以上是关于Liferay JSF服务构建器配置错误的主要内容,如果未能解决你的问题,请参考以下文章

Liferay:jsf portlet 和从带有视图参数的 commandButton 导航

Liferay 7 远程服务访问被拒绝

如何通过 Maven 正确安装和配置 JSF 库?

如何通过 Maven 正确安装和配置 JSF 库?

无法在 Liferay 7.2 中呈现自定义表单字段

Liferay 和 Google 跟踪代码管理器的实施