Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Service Builder 7.1 - Date cannot be resolved to a type
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
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.
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...
<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...
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?
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?
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!
[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!
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.
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.
Hi Christoph ,
Thank you for your reply!
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.
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?
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?
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™