如何使用服务构建器liferay保存自定义实体? 我创建新实体(name = BasicProfile) 并由服务构建者liferay构建但是 保存时发生异常。 我的代码:
BasicProfile basicProfile = new BasicProfileImpl();
basicProfile.setUserId(11701L);
basicProfile.setBirthCertificateSerial(birthCertificate);
basicProfile.setCreateDate(new Date());
basicProfile.setFatherName(fatherName);
basicProfile.setExtCustId(acceptorNumber);
basicProfile.setMobileNumber(telNumber);
basicProfile.setNationalCode(nationalCode);
basicProfile = BasicProfileLocalServiceUtil.addBasicProfile(basicProfile);
答案 0 :(得分:1)
在BasicProfileLocalServiceImpl.java中创建以下方法:
public BasicProfile create(long userId, String birthCertificate, String fatherName, String acceptorNumber, String telNumber, String nationalCode) throws Exception {
long id = counterLocalService.increment();
BasicProfile obj = createBasicProfile(id);
obj.setUserId(userId);
obj.setBirthCertificateSerial(birthCertificate);
obj.setCreateDate(new Date());
obj.setFatherName(fatherName);
obj.setExtCustId(acceptorNumber);
obj.setMobileNumber(telNumber);
obj.setNationalCode(nationalCode);
obj = updateProduct(obj);
return obj;
}
然后在您的代码中调用该方法来创建一个新对象:
BasicProfile basicProfile = BasicProfileLocalServiceUtil.create(userId, birthCertificate, fatherName, acceptorNumber, telNumber, nationalCode);