RE: Service Builder 7.1 - Date cannot be resolved to a type

Kevin Neibarger, modified 6 Years ago. Regular Member Posts: 105 Join Date: 2/2/18 Recent Posts
I'm currently seeing when generating service layer classes with SB in Liferay 7.1. It appears to not add the import java.util.Date for the model implementation generated class. My entity is defined

​​​​​​​<entity name="InterventionAgingReportCarePlan" table="InterventionAgingReportCarePlan" local-service="true" data-source="baycarePopulation" remote-service="false" uuid="false">

<column name="upi" db-name="UPI" type="int" primary="true" />

<column name="prm" db-name="PRM" type="String" />

<column name="practice" db-name="Practice" type="String" primary="true" />

<column name="practiceStatus" db-name="PracticeStatus" type="String" />

<column name="secondaryStatus" db-name="SecondaryStatus" type="String" />

<column name="fullName" type="String" />

<column name="programStatus" db-name="ProgramStatus" type="String" />

<column name="DOD" type="Date" />

<column name="Deceased" type="String" />

<column name="payer" type="String" />

<column name="category" type="String" primary="true" />

<column name="subCategory" type="String" primary="true" />

<column name="detail" type="String" primary="true" />

<column name="caseOwner" type="String" />

[b]<column name="dateAdded" type="Date" primary="true" />[/b]

<column name="assignedTo" type="String" />


<column name="status" type="String" />

<column name="met" type="String" />

<column name="closedReason" type="String" />

<column name="closedDate" type="Date" />

<column name="closedBy" type="String" />


</entity>

And when I've built it, I see the generated Model in the *-api classes shows errors "Date cannot be resolved to a type". And, yes, it's because java.util.Date is not in the imports.

public static final Accessor<interventionagingreportcareplan, date> DATE_ADDED_ACCESSOR =

new Accessor<interventionagingreportcareplan, date>() {

@Override

public Date get(

InterventionAgingReportCarePlan interventionAgingReportCarePlan) {

return interventionAgingReportCarePlan.getDateAdded();

}


@Override

public Class<date> getAttributeClass() {

return Date.class;

}


@Override

public Class<interventionagingreportcareplan> getTypeClass() {

return InterventionAgingReportCarePlan.class;

}

};</interventionagingreportcareplan></date></interventionagingreportcareplan,></interventionagingreportcareplan,>


I had a similar issue with a column that was referenced as a Date but was actually a String, but the column ​​​​​​​in this case is in fact a type of datetime in MySQL DB

Can anyone tell me why the java.util.Date would not be imported in the generated class?  I've used this data type in other entities with no problem...
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Hmm, I copied your entity now in a 7.1 test project and I get an error when building the service:

java.lang.IllegalArgumentException: Primary key dateAdded of entity InterventionAgingReportCarePlan must be an int, long, or String service.input.file=${service.file}

Did you do something special? Some flags?
Claudiu Teodorescu, modified 6 Years ago. New Member Posts: 13 Join Date: 2/25/15 Recent Posts
Hi, I'm working with Liferay 7.1.3 GA4 and I get the same error and I try to run Liferay build-service using Liferay Developer Studio 3.6.0: 
[ERROR] Failed to execute goal com.liferay:com.liferay.portal.tools.service.builder:1.0.292:build (default-cli) on project MyProject-service: Primary key time of entity AAAA must be an int, long, or String -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
My service.xml file:
<service-builder  package-path="aaaa.bbbb.cccc">
    <namespace>AAAA</namespace>
    <entity name="AAAA" local-service="true" table="aaaa_bt" remote-service="true">
        <column name="time" type="Date" primary="true"></column>
        <column name="a" type="int" primary="true"></column>
        <column name="b" type="int" primary="true"></column>
        <column name="c" type="boolean"></column>
        <column name="d" type="boolean"></column>
        <column name="e" type="String"></column>
        <order>
            <order-column name="time" order-by="desc"></order-column>
        </order>
    </entity>
</service-builder>

 workspace pom.xml
[url=http://<liferay.workspace.bundle.url>https://releases-cdn.liferay.com/portal/7.1.3-ga4/liferay-ce-portal-tomcat-7.1.3-ga4-20190508171117552.tar.gz</liferay.workspace.bundle.url>]<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <liferay.workspace.bundle.url>https://releases-cdn.liferay.com/portal/7.1.3-ga4/liferay-ce-portal-tomcat-7.1.3-ga4-20190508171117552.tar.gz</liferay.workspace.bundle.url>
[url=http://[url=http://<liferay.workspace.bundle.url>https://releases-cdn.liferay.com/portal/7.1.3-ga4/liferay-ce-portal-tomcat-7.1.3-ga4-20190508171117552.tar.gz</liferay.workspace.bundle.url>]</properties>][url=http://<liferay.workspace.bundle.url>https://releases-cdn.liferay.com/portal/7.1.3-ga4/liferay-ce-portal-tomcat-7.1.3-ga4-20190508171117552.tar.gz</liferay.workspace.bundle.url>]</properties>

service pom.xml:
<plugin>
                <groupId>com.liferay</groupId>
                <artifactId>com.liferay.portal.tools.service.builder</artifactId>
                <version>1.0.292</version>
                <configuration>
                    ....
                </configuration>
 </plugin>

I don't know how to solve this error.Thank you!
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Are you really sure you want a composite key with so many columns (marked as primary=true)?  In your original example you have 6 of them. Looks quite suspicious to me. Are you really sure, you need dateAdded to be part of the primary key?

Anyway, obviously you need to remove primary="true" from the time column to get it working. I am not sure, what your intention and usecase is, but maybe you should just use a single column with a long or something as the primary key.
Amos Fong, modified 6 Years ago. New Member Posts: 13 Join Date: 2/25/15 Recent Posts
Hi Christoph ,

Thank you for your reply!

Christoph Rabel:
Are you really sure you want a composite key with so many columns (marked as primary=true)?  In your original example you have 6 of them. Looks quite suspicious to me. Are you really sure, you need dateAdded to be part of the primary key?


As you can see in the above comment I need a composite key with 3 columns, because in this way I'm sure that I do not have duplicates, this combination should be unique.

Christoph Rabel:
Anyway, obviously you need to remove primary="true" from the time column to get it working. I am not sure, what your intention and usecase is, but maybe you should just use a single column with a long or something as the primary key.


Yes, for the moment I created an id column with type int but I think to change to long since I have already 462 milions of records in the table.

My question is if this error:   [ERROR] Failed to execute goal com.liferay:com.liferay.portal.tools.service.builder:1.0.292:build (default-cli) on project MyProject-service: Primary key time of entity AAAA must be an int, long, or String -> [Help 1] 

Is something that l did something wrong or Liferay does not allow me anyway to use in the primary key columns which are Date?

​​​​​​​