Pawan
Pawan

Reputation: 32321

Liferay 6 is not Updating Custom Table Created in MySQL

I am using Liferay 6.1

I have created a Table in mysql as shown

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

This is my 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">
        <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>

This is my BookLocalServiceImpl class

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

}

Inside the processAction class , i have added this way

BookLocalServiceUtil.addBook(userId, userName);

But the problem is that , the Liferay Framework has created a New table by name library_book and updated that table .

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

Where as my Table Book is empty

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

Please let me know how to make the table Book gets Updated , but not library_book

Upvotes: 0

Views: 777

Answers (2)

yannicuLar
yannicuLar

Reputation: 3133

The entities created in the actual database are named as [namespace]_[entityName]. Since your namespace is "Library", and the entity is "Book", the resulting table is "library_book", so what you got is quite normal

However, you don't need, and shouldn't search using mysql commands. In most cases, you should use the 'Finder' feature that is provided with service builder, I suggest you take a complete starting tutorial on ServiceBulder , you can't miss that

Upvotes: 1

Biswajit
Biswajit

Reputation: 2506

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>

Upvotes: 1

Related Questions