Im trying to insert a json taxistaPonto in database using Ajax with JQuery via POST, with other entity without foreign key was fine, but i don't know how to insert this entity with foreign keys. Im sending the requests in Json format. Maybe my json isnt in right format? How can i insert this entity in my database?

我试图在数据库中使用Ajax和JQuery通过POST插入一个json taxistaPonto,其他没有外键的实体很好,但我不知道如何使用外键插入此实体。我以Json格式发送请求。也许我的json不是正确的格式?如何在我的数据库中插入此实体?

Model:

@Entity(name="taxistaPonto")
public class TaxistaPonto {

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

    @OneToOne
    @JoinColumn(name = "fk_taxista",nullable=false)
    private Taxista taxista;

    @OneToOne
    @JoinColumn(name = "fk_ponto",nullable=false)
    private Ponto ponto;

    public TaxistaPonto() {
        super();
    }

    public TaxistaPonto(Integer id, Taxista taxista, Ponto ponto) {
        super();
        this.id = id;
        this.taxista = taxista;
        this.ponto = ponto;
    }//... getters and setters

Controller:

@Controller
@Path("/taxistaponto")
public class TaxistaPontoController { 

    @Inject
    private Result result;
    @Inject
    private TaxistaPontoDAO taxistaPontoDAO;

    @Consumes("application/json")
    @Post("/add")
    public void add(TaxistaPonto taxistaPonto){
        taxistaPontoDAO.salvar(taxistaPonto);
    }
}

DAO:

public void salvar(TaxistaPonto taxistaPonto) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        try {
            session.persist(taxistaPonto);
            session.getTransaction().commit();
        } catch (Exception e) {
            session.getTransaction().rollback();
        }

        HibernateUtil.shutdown(session);
    }

Here is my request:

这是我的要求:

$(document).ready(function(){
    var carro =
    {"descricao" : "carro mt legal", "placa" : "12938713"};

    var taxista =
    {id : 5, "nome" : "12:58", "sexo" : "trans", "login" : "loginmeu", "senha" : "minhasenhsa", carro : carro};;

    var ponto =
    {id : 8,"latitude" : "40", "longitude" : "96"};

    var taxistaPonto =
    {taxista : taxista, ponto : ponto};

    $.ajax({
        type: "POST",
        url: "https://expotaxi.herokuapp.com/taxistaponto/add",
        data: JSON.stringify(taxistaPonto),
        contentType: "application/json",
        dataType: "json",
        success: function(data){
            alert("sucesso");
        },
        error : function(data){
            alert("error");
        }
    });
});

@EDIT:This is the excpetion:

@EDIT:这是一个重要的事情:

and is shown a error like this too "uncaught exception: out of memory"

并显示像这样的错误“未捕获的异常:内存不足”

1 个解决方案

#1


1

Can you check the taxistaPonto Object on Salver method. Can you share the parsing logic/handling request on server end.

你能在Salver方法上检查taxistaPonto对象吗?你能在服务器端共享解析逻辑/处理请求吗?

For your case, you can rectify this error on server end while processing the add request.

对于您的情况,您可以在处理添加请求时纠正服务器端的此错误。

更多相关文章

  1. ASP.NET下使用jQuery UI下的Dialog,服务器端按钮无响应的问题。
  2. HTML H5之ASCII 代码转义字符集实体编号
  3. 如何用c#获取服务器端元素的innerhtml(内部有另一个服务器端控件)
  4. 使用没有实体类的本机SQL查询
  5. PHP获取服务器端的相关信息
  6. 使用ajax在服务器端恢复json时出错
  7. php清理当前目录下的指定文件和空目录(源码),建议服务器端执行
  8. 【动软.Net代码生成器】连接MySQL生成C#的POCO实体类(Model)
  9. 主义通过扩展来破坏对实体的查询

随机推荐

  1. 黑马程序员——java高新技术(下)
  2. (Java)出现/消失JPanel中的JLabel仅在调整
  3. 在Java中,使用DefaultSelenium对象在selen
  4. Eclipse Java开发环境的搭建
  5. java通过映射取得方法对一个类的变量进行
  6. JavaScript基础——变量、作用域和内存问
  7. 如何让我的基本SWT应用程序在Mac OS X 10
  8. 老农过河问题
  9. Fragment中出现java.lang.NullPointerExc
  10. java.nio.ByteBuffer的flip、rewind和com