alisson-gomesc / jkniv

Powering your database/repositories with Java code agnostic from JDBC and SQL
http://jkniv.sf.net
GNU Lesser General Public License v2.1
4 stars 0 forks source link

Calling @PreCallBack twice #6

Closed wquintanilhadasilva closed 5 years ago

wquintanilhadasilva commented 5 years ago

In save operations, the framework is calling @PrePersist methods twice.

alisson-gomesc commented 5 years ago

There isn't @PrePersist annotation. Show me your class please. Which version are you using?

wquintanilhadasilva commented 5 years ago

Sorry, I edited the annotation name. The correct name is @PreCallBack :-)

Method in the business class

    public class Item {

        @Getter() @Setter()
        private String _id;

       @PreCallBack(scope = CallbackScope.ADD)
        public void generateId() {
        if (!this.prefix.equals(EntityPrefix.NONE.toString())) {
            this._id = this.prefix + DateTimeUtils.nowUTCTimeStampString();
        }
        }
    }    

Call the Repository in the service:


    public class ItemService extends BaseService {
        private Repository repository = super.getRepository();
        ...
        public void save(Item item) {
            item = this.repository.add(item);
        }
        ...
    }
alisson-gomesc commented 5 years ago

Sorry about delay, happy new year :)

This error is present in the versions 0.6.0.M43 and 0.6.0.M44, the version 0.6.0.M45 was released fixing that. An unit test case was wrote to not repeat again.

<dependency>
    <groupId>net.sf.jkniv</groupId>
    <artifactId>jkniv-whinstone-couchdb</artifactId>
    <version>0.6.0.M45</version>
</dependency>
alisson-gomesc commented 5 years ago

Fixed 0.6.0.M45 version.