<commit_before>package de.ppi.fuwesta.jpa.helper;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;

import de.ppi.fuwesta.oval.validation.OptimisticLock;

/**
 * Basic Model which contains the id and version.
 * 
 */
@MappedSuperclass
@OptimisticLock
public class VersionedModel {

    /**
     * The identifier of the entity.
     */
    @Id
    @GeneratedValue()
    @Column(unique = true, nullable = false)
    private Long id;

    /**
     * The version of the entity.
     */
    @Version
    @Column(nullable = false)
    private Long version;

    @Transient
    private transient boolean optimisiticLockingViolated = false;

    /**
     * Gets the identifier of the entity.
     * 
     * @return the identifier of the entity
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the identifier of the entity.
     * 
     * @param id the identifier of the entity
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Gets the version of the entity.
     * 
     * @return the version of the entity
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version of the entity.
     * 
     * @param newVersion the new version of the entity
     */
    public void setVersion(final Long newVersion) {
        if (newVersion != null) {
            if (version != null && version.longValue() > newVersion.longValue()) {
                optimisiticLockingViolated = true;
            } else {
                version = newVersion;
            }
        }
    }
}<commit_msg>The newVersion must be always set, because otherwise the model will be resend to the view and a second save will work by partialupdate. This is inconsisten if the update will be done without loading the old model.<commit_after>package de.ppi.fuwesta.jpa.helper;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;

import de.ppi.fuwesta.oval.validation.OptimisticLock;

/**
 * Basic Model which contains the id and version.
 * 
 */
@MappedSuperclass
@OptimisticLock
public class VersionedModel {

    /**
     * The identifier of the entity.
     */
    @Id
    @GeneratedValue()
    @Column(unique = true, nullable = false)
    private Long id;

    /**
     * The version of the entity.
     */
    @Version
    @Column(nullable = false)
    private Long version;

    @Transient
    private transient boolean optimisiticLockingViolated = false;

    /**
     * Gets the identifier of the entity.
     * 
     * @return the identifier of the entity
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the identifier of the entity.
     * 
     * @param id the identifier of the entity
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Gets the version of the entity.
     * 
     * @return the version of the entity
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version of the entity.
     * 
     * @param newVersion the new version of the entity
     */
    public void setVersion(final Long newVersion) {
        if (newVersion != null) {
            if (version != null && version.longValue() > newVersion.longValue()) {
                optimisiticLockingViolated = true;
            }
            version = newVersion;
        }
    }
}
{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.0, 'mean_word_length': 2.188859878154917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3022110', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1029, 'n_words': 326}