Liferay JSF服务构建器配置错误

时间:2017-06-08 06:35:25

标签: jsf liferay liferay-service-builder

是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。如何克服这一点。

2 个答案:

答案 0 :(得分:1)

服务构建器

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

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

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

答案 1 :(得分:1)

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

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