-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Rest with Neo4j: TransactionNotFound
PostPosted: Tue Oct 03, 2017 11:17 am 
Newbie

Joined: Tue Oct 03, 2017 11:08 am
Posts: 2
I am trying to save an entity to the database. When I send the post request, I get status:200 ok but the entity is not saved to the database.
Here is the Person class:
Code:
package com.Neo4jRestAPI;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Person")
public class Person {
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "id")
   private Integer id;
   
   @Column(name="gender")
   private String gender;
   
   @Column(name="dob")
   private String dob;
   
   @Column(name="firstname")
   private String firstname;
   
   @Column(name="middlename")
   private String middlename;
   
   @Column(name="lastname")
   private String lastname;

   private String relationship_type;
   
   private String relationship;
   
   public Person() {}
   
   // getters and setters
   public Integer getId() {
      return id;
   }

   public void setId(Integer id) {
      this.id = id;
   }

   public String getGender() {
      return gender;
   }

   public String setGender(String gender) {
      return this.gender = gender;
   }

   public String getDob() {
      return dob;
   }

   public String setDob(String dob) {
      return this.dob = dob;
   }

   public String getFirstname() {
      return firstname;
   }

   public String setFirstname(String firstname) {
      return this.firstname = firstname;
   }

   public String getMiddlename() {
      return middlename;
   }

   public String setMiddlename(String middlename) {
      return this.middlename = middlename;
   }

   public String getLastname() {
      return lastname;
   }

   public String setLastname(String lastname) {
      return this.lastname = lastname;
   }
   
   public String getRelationship_type() {
      return relationship_type;
   }

   public String setRelationship_type(String relationship_type) {
      return this.relationship_type = relationship_type;
   }
   
   public String getRelationship() {
      return relationship;
   }

   public String setRelationship(String relationship) {
      return this.relationship = relationship;
   }
}


here is the PersonDAO class:
Code:
import org.hibernate.HibernateException;

import com.google.gson.Gson;

public class PersonDAO {

    public void addPerson(Person person){

        try {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistence");
            EntityManager em = emf.createEntityManager();
            EntityTransaction tx = em.getTransaction();
            tx.begin();

            em.persist(person);
            em.flush();     
            tx.commit();
            em.clear();
            em.close();
            emf.close();
            }
        catch ( Exception e ) {
            e.printStackTrace();
        }
    }
}


and here is how I try to send the data:
Code:
@POST
@Path("/person")
@Consumes("application/json")
public Response addPerson(Person person){

     PersonDAO dao = new PersonDAO();

     dao.addPerson(person);

     return Response.ok().build();
}


The stack trace does not show any errors, however, when I use log4j, I get the following error:
Code:
"Neo.ClientError.Transaction.TransactionNotFound","message":"Unrecognized transaction id. Transaction may have timed out and been rolled back


When I remove the
Code:
@GeneratedValue
and specify the id in the json, then the entity is saved. When I try to auto generate the id, then the entity is not saved but the id is generated.
Does anyone know what is causing this behavior?


Top
 Profile  
 
 Post subject: Re: Hibernate Rest with Neo4j: TransactionNotFound
PostPosted: Wed Oct 04, 2017 8:32 am 
Newbie

Joined: Tue Oct 03, 2017 11:08 am
Posts: 2
I was able to fix the issue by changing from tomcat to wildfly 9. I am not sure why tomcat was the issue though. It could be a bug but I am not sure. If someone has an explanation I would like to hear it :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.