请求返回错误数据

时间:2015-07-22 15:11:13

标签: hibernate tapestry ninjaframework

我正在使用NinjaFrameWork作为API(No-REST API)的项目。我们通过请求样式将数据插入数据库:

@Transactional
public Result askCita(Context context, DataCitasAsk cita) {

    manager.getTransaction().begin();
    manager.persist(cita);
    manager.getTransaction().commit();
}

当我们通过这样的请求从数据库收集数据时;但它并不总是返回相同的数据。有时它不会返回最后插入的数据。

@Transactional
public Result listCitas(Context context, DataCitasList cita) {

    if (cita == null) {
        return Results.json().render(false);
    }

    // La IP del cliente
    String ipClient = context.getRemoteAddr();

    EntityManager entityManager = provider.get();
    DbCitas db = DbCitas.getInstance();

    DataCitasListResult vUser = db.listCitas(entityManager, cita);

    return Results.json().render(vUser);
}

public DataCitasListResult listCitas(EntityManager manager,
        DataCitasList data) {
    String uCheck = Cita.QUERY_CLINIC_MONTH;

    Calendar calBefore = Calendar.getInstance();
    Calendar calAfter = Calendar.getInstance();
    calAfter.set(Calendar.MONTH, calAfter.get(Calendar.MONTH) + 1);

    DatabaseController db = DatabaseController.getInstance(manager);
    Query q = db.getQuery(uCheck);
    q.setParameter("dateBegan", calBefore.getTime());
    q.setParameter("dateEnd", calAfter.getTime());
    q.setParameter("idClinic", data.getIdClinic());

    List<Cita> list = q.getResultList();

    DbVetData vData = DbVetData.getInstance();
    VetData clinic = vData.getClinicDb(manager, data.getIdClinic());

    DataCitasListResult rData = new DataCitasListResult();
    rData.setClinica(clinic);
    rData.setCitas(new ArrayList<DataCitasResultItem>());

    if (list.isEmpty()) {
        return rData;
    }

    ArrayList<DataCitasResultItem> lCitas = new ArrayList<DataCitasResultItem>();
    for (Cita cita : list) {
        DataCitasResultItem nCita = new DataCitasResultItem();
        nCita.setAnswered(cita.getDateVet() != null ? true : false);
        nCita.setCreated(spf.format(cita.getCreated().getTime()));
        if (cita.getDateCita() != null) {
            nCita.setDateCita(spf.format(cita.getDateCita().getTime()));
        }
        if (cita.getDateVet() != null) {
            nCita.setDateVet(spf.format(cita.getDateVet().getTime()));
        }
        nCita.setId(cita.getId());
        nCita.setIdMascota(cita.getPet().getId());
        nCita.setNameMascota(cita.getPet().getName());
        nCita.setMotivo(cita.getMotive());
        nCita.setTipoCita(cita.getType().getId());

        //
        lCitas.add(nCita);
    }
    rData.setCitas(lCitas);

    return rData;
}

在数据库中出现;它似乎只是咨询,插入。

我不明白为什么。

PD:我包含了Citas.class定义:

@Entity(name = "citas")
   @Table(name = "citas")
   public class Cita {


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "created")
    private Timestamp created;

    @ManyToOne
    @JoinColumn(name = "id_mascota")
    private Pet pet;

    @Column(name = "date_cita")
    private Calendar dateCita;
    @Column(name = "date_vet")
    private Calendar dateVet;
    @Column(name = "motivo")
    private String motive;
    @Column(name = "sended")
    private long sended;

    @ManyToOne
    @JoinColumn(name = "tipo_cita")
    private CitaType type;

    @ManyToOne
    @JoinColumn(name = "id_clinica")
    private VetData clinica;

    }

0 个答案:

没有答案