I am creating an application backend as with RDF Database.
I am using Jena TDB as backend. I am getting this exception
com.hp.hpl.jena.sparql.JenaTransactionException: Currently in a transaction (location:/home/visittoravi/Documents/Store/DB/Tutor/)
Here is my code in this method exception occurs i have marked it with comments-
public UserDetails loadUserByUsername(String email)
throws UsernameNotFoundException {
org.springframework.security.core.userdetails.User authUser = null;
logger.info("Getting user - " + email);
Dataset ds = datasetManager.getDs();
ds.begin(ReadWrite.READ); // Exception is being thrown here
try {
User user = logUserIn(email);
if (user == null) {
System.out.println("User not found");
throw new UsernameNotFoundException(email);
}
logger.info("role = " + user.getRole());
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority(user.getRole()));
authUser = new org.springframework.security.core.userdetails.User(
email, user.getPassword(), true, true, true, true,
authorities);
ds.commit();
} catch (Exception ex) {
ex.printStackTrace();
logger.error(ex);
ds.abort();
} finally {
ds.end();
}
return authUser;
}
datasetManager.getDs() method -
public Dataset getDs() {
if (ds == null) {
logger.log(Priority.INFO, "Creating TDB dataset at : " + dir);
ds = TDBFactory.createDataset(dir);
getOntModel();
}
return ds;
}
getOntModel() method -
public OntModel getOntModel() {
if (ontModel == null) {
Dataset ds = getDs();
ds.begin(ReadWrite.WRITE);
try {
ontModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM_RULE_INF, ds.getDefaultModel());
createAdminData(ds);
createAllOntClasses();
createAllProperties();
ds.commit();
} catch (Exception ex) {
ex.printStackTrace();
ds.abort();
} finally {
ds.end();
}
}
return ontModel;
}
createAdminData method -
private void createAdminData(Dataset ds) {
Resource admin = getDs().getDefaultModel().createResource(
rnamespace + "User1");
admin.addLiteral(VCARD.UID, 1l);
admin.addLiteral(VCARD.FN, "Admin");
admin.addLiteral(VCARD.NAME, "Admin");
admin.addLiteral(VCARD.EMAIL, "visittoravi@gmail.com");
admin.addLiteral(VCARD.ROLE, "ADMIN");
admin.addLiteral(VCARD.KEY, "password");
}
again in createAllOntClasses() and createAllProperties(); i am creating some ontclasses and properties using ontModel.
As you can see in getDs() method i have created a write transaction and i have also included end transaction(ds.end()). and all the db writing part in getOntModel() method is being reflected in database i checked it in fuseki. and after that i am creating a read transaction and it's throwing this exception.
Please help to identify the problem. Also if you have a better way to deal with such scenario like initializing db at context startup in spring mvc.