从Hibernate实体构建SQL保存、更新、删除查询?

huangapple go评论65阅读模式
英文:

Constructing a SQL save, update, remove query from hibernate entities?

问题

可以通过Hibernate创建原生SQL查询来保存、更新或从数据库中删除特定实体吗?

我正在寻找的内容基本上是这样的:

String sqlQuery = session.save(listOfEntities);
session.execute(sqlQuery);

sqlQuery: "insert into players(id,...) values((10,...),(11,...))"
英文:

Is it possible to create native SQL-queries for saving, updating or removing certain entities from the database via hibernate ?

What i am searching for is pretty much this...

String sqlQuery = session.save(listOfEntities);
session.execute(sqlQuery);

sqlQuery : "insert into players(id,...) values((10,...),(11,...))"

答案1

得分: 1

为什么你需要这些语句?只需执行 session.persist(entity),语句就会被自动执行。

英文:

Why would you need the statements? Just doing session.persist(entity) will execute the statement for you already.

huangapple
  • 本文由 发表于 2020年8月18日 02:22:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/63456566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定