Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sunil Kulkarni
Unable to add new method in XXXPersistenceImpl class
May 4, 2013 12:14 PM
Answer

Sunil Kulkarni

Rank: Junior Member

Posts: 92

Join Date: June 24, 2011

Recent Posts

Hello All,

I am using LR 6.1.1 CE version.

I have created a service.xml with following

 1<?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
 3<service-builder package-path="com.book"
 4    auto-namespace-tables="false">
 5    <author>Sunil Kulkarni</author>
 6    <namespace>MyHook</namespace>
 7
 8    <entity name="Book" local-service="true" remote-service="false">
 9        <column name="messageId" type="long" primary="true" />
10
11        <column name="title" type="String" />
12        <column name="description" type="String" />
13        <column name="createdBy" type="long" />
14        <column name="createdDate" type="Date" />
15        <column name="modifiedBy" type="long" />
16        <column name="modifiedDate" type="Date" />
17
18    </entity>
19
20</service-builder>


and then I run the service builder. Service Builder has generated all the requried service and persistence layer classes.
Now I am trying to add new methos in BookPersistenceImpl class and then run the service builder.

Service builder overwrites all the newly added methods from BookPersistenceImpl class.

How do I new methods at persistnce layer which are generated by Service Builder
David H Nebinger
RE: Unable to add new method in XXXPersistenceImpl class
May 5, 2013 8:12 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6985

Join Date: September 1, 2006

Recent Posts

You can't do this. The persistence layer is totally owned by SB. The only place you can (or should) add code is the XXXLocalServiceImpl class. In this class you can add methods to support alternative queries, DQ, and the like.
Mika Koivisto
RE: Unable to add new method in XXXPersistenceImpl class
May 7, 2013 4:06 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1498

Join Date: August 7, 2006

Recent Posts

You can create XXXFinderImpl where you add your custom finders that are more complex than what SB can autogenerate from service.xml.
Sunil Kulkarni
RE: Unable to add new method in XXXPersistenceImpl class
May 11, 2013 9:06 AM
Answer

Sunil Kulkarni

Rank: Junior Member

Posts: 92

Join Date: June 24, 2011

Recent Posts

Thanks for replying .
However, We can only add finders methods into it.

In my case, I have created one table called as BookCatagory, where I am maintaining the bookid and catagoryid. This is a transaction table and I do not want to provide the service over this table (service Builder generated classes).

When user adds Books entry, I want to insert the data into BookCatagoty table.The BookCatagory table is updated, deleted with Books table.

In this case, how do I approach this issue.
David H Nebinger
RE: Unable to add new method in XXXPersistenceImpl class
May 11, 2013 9:31 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6985

Join Date: September 1, 2006

Recent Posts

You would still define the BookCategory entity. Your BookLocalServiceImpl class can do the creates, adds, and removes as necessary, but it still needs to be defined as an entity.

There is no support in SB for 'hidden' entities that you're trying to define. All entities are public, and the API to access those entities are public also.

We have a similar setup where we have entities that are not meant to be used by external plugins, we deal with this by notifying the team that the methods are not meant to be used. The XxxLocalServiceImpl class that uses the internal entities will make necessary changes using the API in just the way you're describing. It all works just fine.
Alain Dresse
RE: Unable to add new method in XXXPersistenceImpl class
May 11, 2013 10:36 AM
Answer

Alain Dresse

Rank: Junior Member

Posts: 95

Join Date: July 18, 2011

Recent Posts

I believe you can create an entity without the corresponding *Service* classes if you set bothe the localservice and remotes vice attributes to false for your BookCategory entity.