【问题标题】:Persist using stored procedure with return id坚持使用带有返回 id 的存储过程
【发布时间】:2012-07-21 17:51:30
【问题描述】:

PostgreSQL 9.1,休眠 4.1。

如何使用存储过程保留 PropertyTypeEntity(返回 id.GenerationType.IDENTITY 中的问题)
不可能吗?

@Table(name = "property_types", schema = "public", catalog = "")
@Entity
public class PropertyTypeEntity implements IEntity<Long> {

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

  ...
}

【问题讨论】:

  • 存储过程是只生成ID,还是整个插入?

标签: java hibernate postgresql jpa


【解决方案1】:

至少有以下两种方式:

  1. 使用SQLInsert,虽然我不知道 JPA 注释是否存在互操作性问题
  2. 创建自定义生成器,可以从this 博客文章中找到一些示例。

【讨论】:

    猜你喜欢
    • 2012-07-13
    • 2011-09-06
    • 2016-01-12
    • 2018-06-23
    • 2013-06-19
    • 2014-01-27
    • 1970-01-01
    • 2019-09-06
    相关资源
    最近更新 更多