openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cil-Gamir <hannes.visa...@rmb.co.za>
Subject Re: Locking Exception after Persisting new entity
Date Thu, 12 Nov 2009 16:32:35 GMT

This is a test class that shows the error

package simpleTest;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import za.co.rmb.rac.riskRatingEngineWeb.entities.Variable;
import za.co.rmb.rac.riskRatingEngineWeb.service.ThresholdService;
import za.co.rmb.rac.riskRatingEngineWeb.service.VariableService;
import za.co.rmb.rac.riskRatingEngineWeb.service.RegulatorService;;

public class SimpleTest {

    private Logger logger = Logger.getLogger(this.getClass().getName());
    private VariableService variableService = new VariableService();

    public static void main(String[] args) {
        SimpleTest st = new SimpleTest();
        st.doVariables();
    }
    
    private void doVariables(){
        Variable v = getVariableOne();
        logger.info("Found variable:");
        logger.info("ID: " + v.getId());
        logger.info("Description: " + v.getDescription());
        logger.info("Value: " + v.getValue());

        // update variable
        v.setValue(v.getValue() + 1);
        logger.info("New Value: " + v.getValue());
        updateVariable(v);

        logger.info("############################################");

        // get the new variable
        v = getVariableTwo();
        logger.info("Found variable:");
        logger.info("ID: " + v.getId());
        logger.info("Description: " + v.getDescription());
        logger.info("Value: " + v.getValue());
        // update variable again
        v.setValue(v.getValue() + 1);
        logger.info("New Value: " + v.getValue());
        updateVariable(v);        
    }


    private Variable getVariableOne() {
        List<Variable> variables =
variableService.getVariableByType("TestType", "T1", false);
        if (variables.size() > 1) {
            logger.error("More than one variable fetched");
            System.exit(1);
        }
        return variables.get(0);
    }

    private Variable getVariableTwo() {
        List<Variable> variables =
variableService.getVariableByType("TestType", "T3", false);
        if (variables.size() > 1) {
            logger.error("More than one variable fetched");
            System.exit(1);
        }
        return variables.get(0);
    }

    
    public String updateVariable(Variable variable) {
        logger.info("Updating Variable with ID " + variable.getId());

        logger.info("end dating old entity");
        // set the user and end date for the currently active variable
        variable.setEndDate(new Date());
        variable.setUserName("jhv");
        variableService.updateVariable(variable);

          //logger.info("creating new entity");
        Variable v2 = new Variable();
        v2.setDescription(variable.getDescription());
        v2.setStartDate(new Date());
        v2.setName(variable.getName());
        v2.setType(variable.getType());
       v2.setValue(variable.getValue());

        variableService.createVariable(v2);

        return "";
    }

  

}

-- 
View this message in context: http://n2.nabble.com/Re-SOLVED-Re-Locking-Exception-after-Persisting-new-entity-tp3992651p3993974.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message