Liferay 6不是更新在MySQL中创建的自定义表

时间:2013-02-22 19:37:31

标签: mysql liferay-6

我正在使用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)

请让我知道如何让书籍更新,但不是库书目

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:1)

在实际数据库中创建的实体名为[namespace] _ [entityName]。 由于你的命名空间是“Library”,而实体是“Book”,因此得到的表是“library_book”,所以你得到的是很正常的

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