Liferay 7 Service Builder Error [NoClassDefFoundError] - maven

I'm working on Liferay and Salesforce. I'm new to Liferay and I'm experiencing an issue that I spent too much time on.
I have a portlet that I decided to create a Service Builder (named "newService"). Here is my service.xml :
<service-builder package-path="com.fr.liferay">
<namespace>SSB</namespace>
<entity local-service="true" name="Comp" remote-service="false" uuid="true">
<!--<entity name="Foo" table="foo" uuid="true" local-service="true" remote-service="false" data-source="sampleDataSource" session-factory="sampleSessionFactory" tx-manager="sampleTransactionManager">-->
<!-- PK fields -->
<column name="compId" primary="true" type="long" />
<!-- Group instance -->
<column name="groupId" type="long" />
<!-- Audit fields -->
<column name="companyId" type="long" />
<column name="userId" type="long" />
<column name="userName" type="String" />
<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />
<!-- Other fields -->
<column name="compName" type="String" />
<column name="compDesc" type="String" />
<column name="compPath" type="String" />
<!-- Order -->
<!-- References -->
</entity>
</service-builder>
Now, I run the maven command :mvn service-builder:build and it generated the newService-api artifact.
I'm calling the service inside my portlet as follows:
Comp comp = CompLocalServiceUtil.createComp(3);
comp.persist();
I added the newservice-api dependency in the portlet's pom.xml :
<dependency>
<groupId>com.fr.liferay.liferay7-
architecture.portail7.services.newService</groupId>
<artifactId>newService-api</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
On launching my portlet, I get this error :
Caused by: java.lang.NoClassDefFoundError: com/fr/liferay/service/CompLocalServiceUtil
at com.fr.liferay.controllers.TestController.actionTwoMethod(TestController.java:151)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:367)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.doHandle(AnnotationMethodHandlerAdapter.java:354)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.handleAction(AnnotationMethodHandlerAdapter.java:285)
at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:666)
... 181 more
12:55:57,243 ERROR [http-nio-8080-exec-5][render_portlet_jsp:131] null
java.lang.NoClassDefFoundError: com/fr/liferay/service/CompLocalServiceUtil
at com.fr.liferay.controllers.TestController.actionTwoMethod(TestController.java:151)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:71)
at com.liferay.portlet.CheckboxParametersPortletFilter.doFilter(CheckboxParametersPortletFilter.java:57)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:68)
at com.liferay.portlet.CheckboxParametersPortletFilter.doFilter(CheckboxParametersPortletFilter.java:57)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:68)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:105)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at com.liferay.portal.osgi.web.wab.extender.internal.adapter.ServletExceptionAdapter.service(ServletExceptionAdapter.java:68)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:50)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:119)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:115)
at com.liferay.portal.osgi.web.wab.extender.internal.adapter.FilterExceptionAdapter.doFilter(FilterExceptionAdapter.java:46)
at org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration.doFilter(FilterRegistration.java:121)
at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:45)
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:70)
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:117)
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
Any idea how to solve this?

I wanted to write this as comment but it's too long so I can only post it as answer, sorry.
You create your enitity and all persistense/model/etc stuff is done by ServiceBuilder. In Liferay 7 it is represented by two modules: api and service. After maven's "build" and servicebuilder's "build-service" you can use default crud methods such as CompLocalServiceUtil.deleteComp() and others. And you have written that you use CompLocalServiceUtil.createComp(3) which means that you've already overriden that default method in CompLocalServiceImpl.java file. Is it true? If not - it's exactly why you have your error.
If you want to add your own business logic - you should modified (and build-service again) CompLocalServiceImpl, if you want to add you own model - you should modify CompImpl.java
May be I just misunderstand you.

Related

Propel2 Reverse second run has deleted columns

I am new to propel. There doesn't appear to be a version command built in, but composer shows propel2 in my description.
I reverse engineered my scheme and models from the database then took six months off the project, came back, remastered the database directly, deleted the generated-classes, and the generated-reversed-database.
I then ran
propel reverse "mysql:host=localhost;dbname=MyVanLog;user=**;password=**"
When that completed I opened my schema.xml file and visually verified that the fuel price column no longer exists.
<table name="LogEntries" idMethod="native" phpName="Logentries">
<column name="LogEntryId" phpName="Logentryid" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="UserId" phpName="Userid" type="INTEGER" primaryKey="true" required="true"/>
<column name="RvId" phpName="Rvid" type="INTEGER" primaryKey="true" required="true"/>
<column name="Title" phpName="Title" type="VARCHAR" size="45" required="true"/>
<column name="Description" phpName="Description" type="CLOB"/>
<column name="Longitude" phpName="Longitude" type="DECIMAL" size="10" scale="8"/>
<column name="Latitude" phpName="Latitude" type="DECIMAL" size="10" scale="8"/>
<column name="Temperature" phpName="Temperature" type="DECIMAL" size="3" scale="1"/>
<column name="Private" phpName="Private" type="VARCHAR" size="1" sqlType="bit(1)" required="true"/>
<column name="CreatedOnUTC" phpName="Createdonutc" type="TIMESTAMP" required="true"/>
<column name="ModifiedOnUTC" phpName="Modifiedonutc" type="TIMESTAMP" required="true"/>
<foreign-key foreignTable="Users" name="FK_36">
<reference local="UserId" foreign="UserId"/>
</foreign-key>
<foreign-key foreignTable="Rvs" name="FK_40">
<reference local="RvId" foreign="RvId"/>
<reference local="UserId" foreign="UserId"/>
</foreign-key>
<index name="fkIdx_36">
<index-column name="UserId"/>
</index>
<index name="fkIdx_40">
<index-column name="RvId"/>
<index-column name="UserId"/>
</index>
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
Then I run propel build to generate my models. I open my base/LogEntries file and it has all the methods to manipulate the field that is no longer there. I won't paste the entire file, but here is the get method.
/**
* Get the [fuelpriceinvalid] column value.
*
* #return string
*/
public function getFuelpriceinvalid()
{
return $this->fuelpriceinvalid;
}
Does anyone know what I missed?
I had an extra schema.xml file hanging out in the project directories that was being read instead of the one I generated causing the old fields to generate. This was likely just a mistake on my part, not a propel bug.

LifeRay 7 "cannot find symbol" Maven service-builder

Create a json webservice for liferay with:
mvn -X archetype:generate -DarchetypeGroupId=com.liferay -DarchetypeArtifactId=com.liferay.project.templates.service.builder -DarchetypeVersion=1.0.7 -DgroupId=com.paygroup -DartifactId=com.paygroup.liferay.templates.service -DinteractiveMode=false -Dauthor=Author
As a result I got two projects one is an "api" and another is a "service".
The service application has a configuration file (service.xml) that leaves it this way:
<service-builder package-path="com.paygroup.liferay.service">
<namespace>Empresas</namespace>
<entity local-service="true" name="Empresas" remote-service="true" uuid="true">
<column name="empresaName" primary="true" type="String" />
<column name="empresaId" type="long" />
<column name="convenio1" type="String" />
<column name="convenio2" type="String" />
<column name="convenio3" type="String" />
<column name="descripcion" type="String" />
<column name="activo" type="boolean" />
<column name="fecha" type="Date" />
<order by="asc">
<order-column name="empresaId" />
</order>
<finder name="EmpresaName" return-type="Collection">
<finder-column name="empresaName" />
</finder>
<reference entity="AssetEntry" package-path="com.liferay.portlet.asset" />
<reference entity="AssetTag" package-path="com.liferay.portlet.asset" />
</entity>
</service-builder>
Running the service-builder command (mvn service-builder:build) works great but when packaging the project with mvn package there is a long list of class errors that are not found:
[ERROR] /media/media/git/GITLAB/demos/liferay/ejemplo-json-webservice/json-webservice/json-webservice-service/src/main/java/com/paygroup/liferay/service/service/persistence/impl/EmpresasPersistenceImpl.java:[38,46]
package com.paygroup.liferay.service.exception does not exist
[ERROR] /media/media/git/GITLAB/demos/liferay/ejemplo-json-webservice/json-webservice/json-webservice-service/src/main/java/com/paygroup/liferay/service/service/persistence/impl/EmpresasPersistenceImpl.java:[39,42], cannot find symbol
[ERROR] symbol: class Empresas
[ERROR] location: package com.paygroup.liferay.service.model
Why does not the service-builder create these classes?
will the service.xml be misconfigured?
you need to run mvn clean install on parent project.
ex: project name abc. So, you'll get abc-service, abc-api after creating service project. you need to run your command on abc project

Lazy loading hibernate

I use Spring 3 and hibernate 3.6.3.Final. I have to entities A and B. The hbm files are:
A.hbm.xml
<hibernate-mapping>
<class name="com.A" table="A" >
<id name="A_Id" type="string">
<column name="Id" length="100" />
<generator class="foreign">
<param name="property">B</param>
</generator>
</id>
<one-to-one name="B" class="B" constrained="true" fetch="select" ></one-to-one>
<property>...</property>
</class>
</hibernate-mapping>
and B.hbm.xml
<hibernate-mapping>
<class name="com.B" table="B">
<id name="B_Id" type="string">
<column name="Id" length="32" />
<generator class="assigned" />
</id>
...
<one-to-one name="some_A" class="com.A" lazy="proxy"></one-to-one> // FIRST
<one-to-one name="other_A" class="com.A" lazy="proxy" cascade="all" > // SECOND
<formula>other_BSRC_REG_REP_MESSAGE_ID</formula>
</one-to-one>
</class>
</hibernate-mapping>
From #Service I use the following code to get entity B by id:
getHibernateTemplate().get(getEntityClass(), id)
I enabled the show_sql mode in hibernate in order to check if my lazy loading works fine. Unfortunately I don't understand them
When either FIRST or SECOND line is commented out hibernate shows exactly one query (where all of the one-to-one associations are present as join),
When both FIRST and SECOND lines are uncommented hibernate shows two queries, one to get B and second to get an A entity.
Why this happens? Is it because all of the one-to-one association can't be lazy loaded so either they are eagerly loaded as a separate query or "joined" to the original query? If so, why hibernate didn't joined on the A table twice?

How to use single inheritance in propel schema

I need to make a 'Event' class and propel schema with Columns:
id
employee_id
date_start
date_end
type
How to implement the simple inheritance based on the type column.
All classes should extend the abstract Event class.
Initial sub-class:
JoinEvent
can anyone write a schema for it?
I have written schema but not sure whether it is correct or not.
<table name="event" phpName="Event">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="employee_id" type="integer" required="true" />
<column name="date_start" type="date" required="true" />
<column name="date_end" type="date" required="false" />
<column name="type" type="integer" inheritance="single">
<inheritance key="1" class="JoinEvent" extends="Event"/>
</column>
<foreign-key foreignTable="employee" name="FI_event_employee">
<reference local="employee_id" foreign="id" />
</foreign-key>
</table>
Please help me.

How to configure Doctrine entities to handle compressed blobs in the database?

I'm using Doctrine 2 as an ORM to the database and i'm having an issue with compressed blobs.
I'm storing text in a compressed blob column in the database. How can i specify this in the entity mapping xml config? I'm currently using type="blob" for this column but this isn't returning a string. I could use type="text" but this returns garbage as it's not uncompressing it.
Can i specify somewhere in my entity config that this text need uncompressing on retrieval and compressing on persisting?
Here's my entity configuration:
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="AccountNote" table="tblAccountNote">
<id name="intAccountNoteId" type="integer">
<generator strategy="AUTO" />
</id>
<field name="intAccountId" type="integer" nullable="false" unique="no" />
<field name="bolHiddenNote" type="boolean" nullable="false" unique="no" />
<field name="binNote" type="blob" nullable="false" unique="no" />
<field name="strHash" type="string" length="32" nullable="true" unique="no" />
<field name="dtmCreated" type="datetime" nullable="false" unique="no" />
<field name="stmTimestamp" type="datetime" nullable="false" unique="no" />
<many-to-one field="objAccount" target-entity="Account" inversed-by="objNotes">
<join-column name="intAccountId" referenced-column-name="intAccountId" />
</many-to-one>
</entity>
</doctrine-mapping>
In the end we decided on handling the compression in the getter and setter and removing it from the schema.

Resources