Skip to main content

Aggregate identifier must be non-null

Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.

For this I have force fully passed a random variable to CreateRemarkCommand() which is given below: Users.kt class CreateRemarkEvent(val id: Int, val remarkDto: RemarkDto) : BaseEvent(); class CreateRemarkCommand(val id: Int, val remarkDto: RemarkDto) : BaseCommand(); RemarksController: public BaseResponseDto storeRemarks(@RequestBody RemarkDto remarkDto){ remarkDto.setRemarkDate(new Date()); remarkDto.setUserType(UserType.SUBSCRIBER); int remarkAggregate = Integer.parseInt(RandomStringUtils.randomNumeric(6).toString()); CreateRemarkCommand remarkCommand = new CreateRemarkCommand(remarkAggregate, remarkDto); commandBus.dispatch(new GenericCommandMessage<>(remarkCommand)); log.info("Dispatched command"); return BaseResponseDto.builder() .statusCode(StatusCode.SUCCESS) .message("Remarks Created.") .build(); } EventSourcingHandler: @EventSourcingHandler public void on(CreateRemarkEvent event) { RemarkDto remarkDto = event.getRemarkDto(); this.id = event.getId(); this.adminId = remarkDto.getAdminId(); this.userId = remarkDto.getUserId(); this.userType = remarkDto.getUserType(); this.remark = remarkDto.getRemark(); this.remarkDate = remarkDto.getRemarkDate(); } @EventHandler: @EventHandler public void handle(CreateRemarkEvent event) { RemarkDto remarkDto = event.getRemarkDto(); UserRemarks remarks = new UserRemarks(); remarks.setUserId(remarkDto.getUserId()); remarks.setAdminId(remarkDto.getAdminId()); remarks.setUserType(remarkDto.getUserType()); remarks.setRemark(remarkDto.getRemark()); remarks.setRemarkDate(remarkDto.getRemarkDate()); remarksQueryRepository.save(remarks); log.info("Successfully saved remarks of user Id" + remarkDto.getUserId()); } @CommandHandler: @CommandHandler public void handle(CreateRemarkCommand command) throws Exception { remarksRepository.newInstance(() -> new UserRemarks(command.getId(), command.getRemarkDto())); } RemarkAggregate: public class UserRemarks { @AggregateIdentifier private Integer id; private String remark; private Integer adminId; private Integer userId; private UserType userType; private Date remarkDate; public UserRemarks(int id, RemarkDto remarkDto) { apply(new CreateRemarkEvent(id, remarkDto)); }

Comments

Popular posts from this blog

Q & A Chapter 1 | Internet Basics | Class 10 CBSE | Computer Application

 Q & A of Chapter 1 Internet Basics A. Tick the correct options – 1. (b) TCP/IP 2. (a) Internet Service Provider 3. (a) URL 4. (b) HTTP 5. (a) Bridge 6. (a) home page 7. (d) All of these 8. (b) Domain Naming System 9. (b) Rules 10. (d) ARPANET B. Very Short Answer Type Questions – 1. In the URL http://www.myfirm.co.in/about.html , what do the following components depict? (a) http                                                 (b) in (a) Http represents a type of server and the protocol on the Internet (b) ‘in’ represents the domain extension of the website. 2. In the URL http://www.favmusic.com/contactus.html what does www.favmusic stand for? www.favmusic represents the domain name i.e. favmusic in www. 3. W...

Bit by Bit | Chapter 3 Working with Queries, Forms and Reports | Class 8 CBSE | Computer Application

Working with Queries, Forms and Reports Exercise Solution A. Tick the correct option – 1. (d) Datasheet View 2. (c) Three 3. (c) Four 4. (b) Datasheet View 5. (d) Filter 6. (b) Create B. Fill in the blanks – 1. Query 2. Form 3. Objects 4. Design 5. Report 6. Result C. State True or False – 1. T 2. F 3. T 4. T 5. F 6. T D. Answer the following questions – 1. What is Query? A query is a method of getting answers to questions on data. It is used to retrieve selective data satisfying specific criteria. 2. Differentiate between Form and Report. Forms allow you to add and update data in a table, one record at a time, while reports are an effective way to present data in printed format. You can customize the appearance of tabular data on a report. 3. How can you specify multiple conditions while designing a query? Specifying the condition in the Criteria row for more than one field will result in a query that will select only those records...

Escape Sequence

What are Escape Sequence characters? Give example. Escape Sequence is a character that contains a special meaning. Escape Sequence Description \n New line \\ Backslash \’ Single quotation \” Double quotation \a Bell \b Backspace \r Carriage return \t Horizontal tab \v Vertical tab