0

我正在使用 Liferay 6.1

我在 mysql 中创建了一个表,如图所示

create table Book (
    bookId bigint(10) not null primary key,
    companyId bigint(10) null ,
        userId bigint(10) null ,
    userName VARCHAR(75)
);

这是我的 service.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<service-builder package-path="com.test">
    <author>sai</author>
    <namespace>Library</namespace>
    <entity name="Book" local-service="true" remote-service="false">
        <column name="bookId" type="long" primary="true" />
        <column name="companyId" type="long" />
        <column name="userId" type="long" />
        <column name="userName" type="String" />
    </entity>
</service-builder>

这是我的 BookLocalServiceImpl 类

public class BookLocalServiceImpl extends BookLocalServiceBaseImpl {
    public Book addBook(long userId, String userName) throws PortalException,
            SystemException {
        long bookId = CounterLocalServiceUtil.increment(Book.class.getName());
        Book book = bookPersistence.create(bookId);
        book.setCompanyId(1126);
        book.setUserId(1126);
        book.setUserName(title);
        book = bookPersistence.update(book, false);
        return book;
    }

}

在 processAction 类中,我添加了这种方式

BookLocalServiceUtil.addBook(userId, userName);

但问题是,Liferay 框架创建了一个名为 library_book 的新表并更新了该表。

  mysql> select * from library_book;
+--------+-----------+--------+----------+
| bookId | companyId | userId | userName |
+--------+-----------+--------+----------+
|      1 |      1126 |   1126 | saibaba  |
+--------+-----------+--------+----------+
1 row in set (0.00 sec)

我的表书是空的

mysql> select * from Book;
Empty set (0.00 sec)

请让我知道如何使表格 Book 得到更新,但不是 library_book

4

2 回答 2

1
Have you created book table in mysql? if yes then mentioned it in service.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<service-builder package-path="com.test">
    <author>sai</author>
    <namespace>Library</namespace>
    <entity name="Book" local-service="true" remote-service="false" table="book">
        <column name="bookId" type="long" primary="true" />
        <column name="companyId" type="long" />
        <column name="userId" type="long" />
        <column name="userName" type="String" />
    </entity>
</service-builder>
于 2013-02-23T18:47:23.177 回答
1

在实际数据库中创建的实体被命名为 [namespace]_[entityName]。由于你的命名空间是“图书馆”,实体是“书”,结果表是“图书馆书”,所以你得到的是很正常的

但是,您不需要也不应该使用 mysql 命令进行搜索。在大多数情况下,您应该使用服务构建器提供的“查找器”功能,我建议您在ServiceBulder上学习完整的入门教程,您不能错过

于 2013-02-25T09:18:36.063 回答