2013-02-22 16 views
0

我使用的Liferay 6.1的Liferay 6並沒有更新的自定義表中創建MySQL中

我創建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) 

請讓我知道如何使表簿被更新,但不library_book

回答

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

在實際創建的實體數據庫被命名爲[namespace] _ [entityName]。 由於你的命名空間是「庫」,而實體是「書」,所以得到的表是「library_book」,所以你得到的是非常正常的

但是,你不需要,也不應該使用搜索mysql命令。在大多數情況下,您應該使用服務構建器提供的「Finder」功能,我建議您在ServiceBulder上完成一個完整的入門教程,您不能錯過

相關問題