Foros de discusión

Service builder overwrites PersistenceImpl source code

thumbnail
Artur Linhart, modificado hace 15 años.

Service builder overwrites PersistenceImpl source code

Expert Mensajes: 459 Fecha de incorporación: 13/09/07 Mensajes recientes
Hello,

I use the service builder for creation of the services in ext environment and I encounter a problem - if I regenerate the defined services, the service builder deletes and generates again for me also the XXXPersistenceImpl, which I understood as a class, where I should write also my own methods which should be then visible in XXXPersistence interface (similary to the behavior of XXXLocalServiceImpl and XXXServiceImpl).

Does anybody some solution how to use service builder if I wat to create my own persistence methods? Do I have to create my own persistence class, or is there some way how to extend the default generated XXXPersistenceImpl class without the problem it will be overwritten by the next start of service builder with the corresponding service.xml file?

I use Liferay 5.1.2 also with service builder coming int he official bundle with it...

Thanks in advance for any clues, Artur
thumbnail
Christianto Sahat, modificado hace 15 años.

RE: Service builder overwrites PersistenceImpl source code

Regular Member Mensajes: 179 Fecha de incorporación: 25/09/07 Mensajes recientes
Artur Linhart:
Hello,

I use the service builder for creation of the services in ext environment and I encounter a problem - if I regenerate the defined services, the service builder deletes and generates again for me also the XXXPersistenceImpl, which I understood as a class, where I should write also my own methods which should be then visible in XXXPersistence interface (similary to the behavior of XXXLocalServiceImpl and XXXServiceImpl).

Does anybody some solution how to use service builder if I wat to create my own persistence methods? Do I have to create my own persistence class, or is there some way how to extend the default generated XXXPersistenceImpl class without the problem it will be overwritten by the next start of service builder with the corresponding service.xml file?

I use Liferay 5.1.2 also with service builder coming int he official bundle with it...

Thanks in advance for any clues, Artur


Hi Artur,

You can just create a new PersistenceImpl class, let's say, XXXPersistenceImplChild, extending XXXPersistenceImpl class. After that, in your service.xml, you can edit the persistence-class attribute, like this :


<entity name="Project" local-service="true" remote-service="false" persistence-class="com.ext.portlet.myportlet.service.persistence.XXXPersistenceImplChild">
</entity>


Then you can override any method from XXXPersistenceImpl in XXXPersistenceImplChild without service builder overriding this new class everytime you regenerate using service builder.

Hope it helps.

Chris
thumbnail
Artur Linhart, modificado hace 15 años.

RE: Service builder overwrites PersistenceImpl source code

Expert Mensajes: 459 Fecha de incorporación: 13/09/07 Mensajes recientes
Hello, Chris,

I knew there was some solution for this, but I forgot I changed my configuration - Thank You.

I would be great, if in the generated PersistenceImpl class would be also the obvious comment this class will be overwritten every time.. There is no javadoc like in the other, always regenerated classes.

with thanks and regards, Artur
thumbnail
Michael Weber, modificado hace 13 años.

RE: Service builder overwrites PersistenceImpl source code

New Member Mensajes: 21 Fecha de incorporación: 13/05/10 Mensajes recientes
Hello,

I know this post is old. But I have a similar question.

In my service builder xml I make use of the service facade, which means an entity without columns:


<entity name="SOMyServiceFacade" local-service="true" remote-service="true" persistence-class="com.mypackage.service.persistence.SOMyServiceFacadePersistenceImpl">
	</entity>


The local and remote services are correctly generated. But no persistence interfaces and persistence implementation are generated. I already use this facade for executing querys with the wrapped hibernate session of BasePersistenceImpl. So I created the persistence interface and the implementation+PersistenceUtil manually in the service-folder and re-run the service builder. Finally, I've added a bean entry in the portlet-spring.xml:


<bean id="com.mypackage.service.persistence.SOMyServiceFacadePersistence" class="com.mypackage.service.persistence.SOMyServiceFacadePersistenceImpl" parent="basePersistence" />

Everything works fine. But now everytime I execute the service builder once again he overwrites my modified spring-portlet.xml. Is there a way arround to prevent this manual step and tell that there are some persistence classes for the defined facade? Thanks for your advices in advance.

Regards,

Michael
thumbnail
Artur Linhart, modificado hace 13 años.

RE: Service builder overwrites PersistenceImpl source code

Expert Mensajes: 459 Fecha de incorporación: 13/09/07 Mensajes recientes
Hello, Michael,

sorry for longer delay, I have not been present in the forum in the last months and I did not receive the nofigication e-mail...

AS far as I remember, the problem is, You specify the value

persistence-class="com.mypackage.service.persistence.SOMyServiceFacadePersistenceImpl"

there. I hope I say nothing wrong (it is already some time I was deeper in this topic) but this attribute is there only for such a cases, If You have your own specific persistence and you want to force the service builder not to generate the persistence class directly. In this case you have to also put your spring and hibernate definitions related to such a custom persistence into separate configuration files, which should be referenced from the global configuration files and will not be overwritten.

If you just remove the attribute persistence-class, I guess the service builder will normally generate or refresh existing persistence class with the corresponding name. You can try and post me here a message if I am wrong or not :-)

with regards, Artur
thumbnail
Artur Linhart, modificado hace 13 años.

RE: Service builder overwrites PersistenceImpl source code

Expert Mensajes: 459 Fecha de incorporación: 13/09/07 Mensajes recientes
Aaaa, I see, Christian already lend me to the solution of the similar problems 2 years ag in this thread :-)

What is the functionality YOu want to customize in the persistence impl class, so what is the reason You explicitely specify persistence-class attribute in service.xml?
thumbnail
Michael Weber, modificado hace 13 años.

RE: Service builder overwrites PersistenceImpl source code

New Member Mensajes: 21 Fecha de incorporación: 13/05/10 Mensajes recientes
Hello Arthur,

thank you for your advice. Basically, I just wanted to generate one own Persistence class to tune up some queries avoiding to load whole entities. Finally I got it to work:
I'm using the context-xml "ext-spring.xml" in the META-INF-folder to register my own spring beans (so also my own persistence classes). This file is also referenced in service.properties. It works as I expected. In this way I could also integrate activemq-JMS-functionality into my portlet+JBoss AS 5.1. It is really a nice feature to load then any Bean I need with the com.liferay.portal.kernel.bean.PortletBeanLocatorUtil-class.

Regards,
Michael
Chandarsekhar Rajoli, modificado hace 9 años.

RE: Service builder overwrites PersistenceImpl source code

New Member Mensaje: 1 Fecha de incorporación: 11/12/13 Mensajes recientes
Michael Weber:
Hello Arthur,

thank you for your advice. Basically, I just wanted to generate one own Persistence class to tune up some queries avoiding to load whole entities. Finally I got it to work:
I'm using the context-xml "ext-spring.xml" in the META-INF-folder to register my own spring beans (so also my own persistence classes). This file is also referenced in service.properties. It works as I expected. In this way I could also integrate activemq-JMS-functionality into my portlet+JBoss AS 5.1. It is really a nice feature to load then any Bean I need with the com.liferay.portal.kernel.bean.PortletBeanLocatorUtil-class.

Regards,
Michael


Hello Michael,

I have similar issue, I want to generate own Persistance class to add update queries, Can you please elaborate the required changes. Thanks you
Advait Trivedi, modificado hace 9 años.

RE: Service builder overwrites PersistenceImpl source code

Junior Member Mensajes: 56 Fecha de incorporación: 30/03/10 Mensajes recientes
This is how I get it to work in my 6.2 ee

1. add bean definition to my ext-spring.xml:
<bean id="CustomExtBlogsPersistenceImpl"
class="CustomExtBlogsPersistenceImpl"
par­ent="basePersistence" />

2. retrieve this bean as follows in Service:
CustomExtBlogsPersistenceImpl p = (CustomExtBlogsPersistenceImpl) com.liferay.portal.kernel.bean.PortletBeanLocatorUtil
.locate(ClpSerial­izer
.getServletContextName(),
CustomExt­BlogsPersistenceImpl.class.getName());

Note: omitted package names from above for the sake of brevity
Balu Sasidharan, modificado hace 13 años.

RE: Service builder overwrites PersistenceImpl source code

New Member Mensajes: 8 Fecha de incorporación: 18/08/10 Mensajes recientes
HI Artur,


I have the following problems

1.I have one portlet ,I added 5 tables to the existing database schema. In my portlet I'm using Hibernate to access the database.How can I make use of the liferay database classes for database operations?

2.When I generated the classes using eclipse for the liferay db schema,it does not contain the relationships ie Usually the User object need to have a getOrganization method but it is not there in the hibernate generated classes. In the liferay db classes we can see getOrganization ,getRole etc.. methods.

NB:Earlier I had another database ,Now I moved those tables into the liferay db And I want o get the User db Object

3. How can I get the User attributes from my portlet session?

I'm very much troubled with these problems?

help me please......

Thanks
Balu
thumbnail
Michael Weber, modificado hace 13 años.

RE: Service builder overwrites PersistenceImpl source code

New Member Mensajes: 21 Fecha de incorporación: 13/05/10 Mensajes recientes
Hi Balu,

I'm also quietly new to Liferay but I will try to answer your questions as well as I can.

Balu Sasidharan:


1.I have one portlet ,I added 5 tables to the existing database schema. In my portlet I'm using Hibernate to access the database.How can I make use of the liferay database classes for database operations?

2.When I generated the classes using eclipse for the liferay db schema,it does not contain the relationships ie Usually the User object need to have a getOrganization method but it is not there in the hibernate generated classes. In the liferay db classes we can see getOrganization ,getRole etc.. methods.



The liferay database operations are built on top of hibernate. If you look to the source code, Liferay Session and Liferay Query are just Wrappers to the Hibernate Session using Hibernate Criterion for querying the database. Basically, you need to use the service builder xml to make use of the liferay database operations (Data access objects and data access services for each entity). The service builder can generate everything for you. To retrieve than relational objects you need to implement by yourself these dynamic queries in the ModelImpl-Classes, rerunning the service builder to rebuild your own service api.

Balu Sasidharan:

3. How can I get the User attributes from my portlet session?


If you make use of the liferay API you can get User with this snippet:

com.liferay.portal.theme.ThemeDisplay themeDisplay = (com.liferay.portal.theme.ThemeDisplay)renderRequest.getAttribute(com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
com.liferay.portal.model.Account a = themeDisplay.getAccount();
com.liferay.portal.model.User u = themeDisplay.getUser();


These are all objects of the Liferay MVC. In the book "Liferay in Action" of the Author Richard Sezov you will find more information about this. Hope that helps.

Regards,
Michael
thumbnail
Artur Linhart, modificado hace 13 años.

RE: Service builder overwrites PersistenceImpl source code

Expert Mensajes: 459 Fecha de incorporación: 13/09/07 Mensajes recientes
Hello, Balu,

I think Michael already wrote everything important. maybe just to Your first point "I have created 5 new tables in liferay scheme" the way which is preferred by service builder is you define first the fields in the service builder and let then generate the sql scripts for the modification of the database. You can customize also some things in service xml related to the DB schema, like table name, field name, etc.

Example of one from my older service.xml (used with Liferay 5.1.2), which is part of some user club portlets application we have developed for the purposes of our customers:

<!--?xml version="1.0"?-->


<service-builder package-path="com.bcpraha.prodline.liferayenh.userclub.bl.core.usergroup">
	<author>Artur Linhart</author>
	<namespace>BCKDS_LRP_UC</namespace>


	<entity name="ClubUsergroup" local-service="true" remote-service="true" table="bckds_uc_usergroup" cache-enabled="true">

		<!-- PK fields -->

		<column name="clubUsergroupId" type="long" primary="true" db-name="id_uc_usergroup" />

		<!-- Group instance -->

		<column name="groupId" type="long" />

		<!-- Audit fields -->

		<column name="companyId" type="long" />
		<column name="changeUserId" type="long" db-name="id_change_user" />
		<column name="createDate" type="Date" />
		<column name="changeDate" type="Date" />

		<!-- Other fields -->

		<column name="name" type="String" db-name="usergroup_name" />
		<column name="description" type="String" db-name="usergroup_description" />
		<column name="active" type="boolean" db-name="usergroup_active" />
		<column name="visible" type="boolean" db-name="usergroup_visible" />
		<column name="externalCode" type="String" db-name="external_usergroup_code" />
		<column name="systemUsergroupId" type="long" db-name="id_system_usergroup" />
		<column name="pointsImportAllowed" type="boolean" db-name="points_import_allowed" />
		<column name="pointsImportRequired" type="boolean" db-name="points_import_required" />
		<column name="pointsImportContainsActivityInformation" type="boolean" db-name="points_import_contains_activity_information" />
		<!-- Points-value which should be considered being as the "inactivity" values, so the user 
			 is set to be inactive in the given user club group. if there are multiple values specified, 
			 they have to be separated by ";"-character: -->
		<column name="pointsImportInactivityValues" type="String" db-name="points_import_inactivity_values" />
		<!-- following field causes there will be thrown no exception and also no action will be taken
		     if the points value is null for the group: -->
		<column name="pointsImportMayContainNullValues" type="boolean" db-name="points_import_may_contain_null_values" />
		<column name="membershipKindImportAllowed" type="boolean" db-name="membership_kind_import_allowed" />
		<column name="membershipKindImportRequired" type="boolean" db-name="membership_kind_import_required" />
		<column name="membershipKindImportContainsActivityInformation" type="boolean" db-name="membership_kind_import_contains_activity_information" />
		<!-- Membership-code value which should be considered being as the "inactivity" values, so the user 
			 is set to be inactive in the given user club group. if there are multiple values specified, 
			 they have to be separated by ";"-character: -->
		<column name="membershipKindImportInactivityValues" type="String" db-name="membership_kind_import_inactivity_values" />
		<!-- following field causes there will be thrown no exception and also no action will be taken
		     if the membership value is null for the group: -->
		<column name="membershipKindImportMayContainNullValues" type="boolean" db-name="membership_kind_import_may_contain_null_values" />
		<!-- Contains the Id of the default membership definition of the membership, assigned to the user
		     before he has got imported the first membership  -->
		<column name="defaultMembershipKindId" type="long" db-name="id_default_membership_kind_definition" />

		<!-- following flag has reason only in the case if for one group 
		     as well membership as points are imported - then the activity can be specified 
		     in both what can lead to the conflict, which is solved by this field: -->
		<column name="membershipActivityOverridesPointsActivity" type="boolean" db-name="membership_activity_overrides_points_activity" />

		<!-- Order -->

		<order by="asc">
			<order-column name="groupId" order-by="asc" />
			<order-column name="externalCode" order-by="asc" case-sensitive="true" />
		</order>
		
		<!-- Finder methods -->

		<finder name="GroupId" return-type="Collection">
			<finder-column name="groupId" />
		</finder>
		<finder name="GroupIdExternalCode" return-type="Collection">
			<finder-column name="groupId" />
			<finder-column name="externalCode" />
		</finder>
		
		<!-- References -->

		<reference package-path="com.liferay.lock" entity="Lock" />
		<reference package-path="com.liferay.portal" entity="Group" />
		<reference package-path="com.liferay.counter" entity="Counter" />
		<reference package-path="com.liferay.portal" entity="UserGroup" />
		
	</entity>
	
	<entity name="ClubUsergroupUserMembership" local-service="true" remote-service="true" table="bckds_uc_usergroup_user_membership" cache-enabled="true">

		<!-- PK fields -->

		<column name="clubUsergroupUserMembershipId" type="long" primary="true" db-name="id_uc_usergroup_user_membership" />

		<!-- Group instance -->

		<column name="groupId" type="long" />

		<!-- Audit fields -->

		<column name="companyId" type="long" />
		<column name="changeUserId" type="long" db-name="id_change_user" />
		<column name="createDate" type="Date" />
		<column name="changeDate" type="Date" />

		<!-- Other fields -->

		<column name="clubUsergroupId" type="long" db-name="id_club_usergroup" />
		<column name="clubUserId" type="Long" db-name="id_club_user" />

		<!-- Order -->

		<order by="asc">
			<order-column name="groupId" order-by="asc" />
			<order-column name="clubUserId" order-by="asc" />
			<order-column name="clubUsergroupId" order-by="asc" />
		</order>
		
		<!-- Finder methods -->

		<finder name="GroupId" return-type="Collection">
			<finder-column name="groupId" />
		</finder>
		<finder name="GroupIdClubUserId" return-type="Collection">
			<finder-column name="groupId" />
			<finder-column name="clubUserId" />
		</finder>
		<finder name="GroupIdClubUserIdClubUsergroupId" return-type="Collection">
			<finder-column name="groupId" />
			<finder-column name="clubUserId" />
			<finder-column name="clubUsergroupId" />
		</finder>
		

		<!-- References -->

		<reference package-path="com.liferay.counter" entity="Counter" />
		<reference package-path="com.liferay.portal" entity="User" />
	</entity>	
</service-builder>