0

我是 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:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\service-classes
 [copy] Copied 9 empty directories to 9 empty directories under D:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\service-classes
[javac] Compiling 38 source files to D:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\service-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:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\lib\jsfguestbook-portlet-service.jar
[delete] Deleting directory D:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\service-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。如何克服这一点。

4

2 回答 2

2

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

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

于 2018-02-28T15:42:53.670 回答
1

服务生成器

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

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

     return guestbookPersistence.findByGroupId(groupId);

3.要创建一个 groupid 和 name find 它看起来类似于您的条目查找器。

    <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);

服务.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.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 之间有一些非常大的变化。您的代码似乎与两者兼容,但您仍应牢记这一点。

于 2017-06-09T06:01:21.533 回答