- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先....我有一个这样的postgres函数:
CREATE OR REPLACE FUNCTION auth.MyFunction (
platform autorizacion.e_tipo_plataforma, //Enum Type
pAppId varchar,
pVersion integer
)
当 e_tipo_plataforma
是:
CREATE TYPE autorizacion.e_tipo_plataforma AS ENUM (
'Web', 'Escritorio', 'Movil', 'Servicio');
如您所见,调用函数的参数是枚举类型
(e_tipo_plataforma)
我正在尝试将此 EnumType 发送到 Postgres CallableStatement
:
String query="{call auth.MyFunction(?,?,?)}";
CallableStatement ps=conn.prepareCall(funcionLlamar);
第一个意图:ps.setObject("p_tipo_plataforma", usuario.tipoPlataforma);
哪里
错误:
java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgCallableStatement.setObject(String,Object) is not yet implemented.
第二个意图:ps.setObject(1, usuario.tipoPlataforma.name());
错误:
function auth.MyFunction(character varying, character varying, integer) does not exist
更新:第三个意图:ps.setObject(1, usuario.tipoPlataforma);
错误:
Can't infer the SQL type to use for an instance of enumerator.TipoPlataforma. Use setObject() with an explicit Types value to specify the type to use.
问题是,如果 postgres 中的函数只接受这种类型,如何将 EnumType 作为参数发送?
最佳答案
您可以将枚举值作为字符串传递(当然,假设您的 Java 和 PostgreSQL 枚举的名称匹配!),并把将字符串转换为枚举的繁重工作留给数据库:
ps.setString("p_tipo_plataforma", usuario.tipoPlataforma.name());
关于java - 将 EnumType 传递给 Postgres 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52451677/
我的灵感来自java.sql.SQLException: Data truncated for column 'gender' at row 1 for enum . 我有这个枚举 public en
有一个 hibernate 映射遗留数据库,我想使用 EnumTypes 将包含带空格的字符串常量的某些列映射到某个 Enum 类。 映射: @Entity @Table(name = "OPERAT
这里是 C# 新手。我正在浏览 MSDN,浏览 enum 方法,但我无法分辨 TEnum 和 enumType 之间的区别。 public static bool TryParse( string v
使用 Spring JPA 时,枚举值不会作为 EnumType.STRING 保留,而是作为子实体的 EnumType.ORDINAL 值保留 我的 Employee 实体具有名称、ENUM 字段和
如何为定义映射将设置为 enumType:'identity'? 在Grails 3.3中,enumType成为Enums with id的必需项(对于3.2,它无需任何其他定义即可工作)。 使用枚举
我正在开发 C# 应用程序并且我有以下枚举: public enum TourismItemType : int { Destination = 1, PointOfInteres
首先....我有一个这样的postgres函数: CREATE OR REPLACE FUNCTION auth.MyFunction ( platform autorizacion.e_tipo
这是我写的: public class JavaApplication4 { private RunMode runMode; private enum RunMode {
目前,我的项目使用@Enumerated(EnumType.ORDINAL),所以当我按此列排序时,它是根据枚举中的顺序排序的,这工作正常。但我需要向 enum 添加一些额外的值,这些值需要插入到枚举
我有一个 mysql 表,我在其中存储枚举字符串值。 我的模型有注释: @Enumerated(EnumType.STRING) 我的枚举看起来像: public enum SomeEnum {
我有以下映射: public enum JobType { CLEANER, CRAWLER, ... } public class JobId implements Seriali
(MySQL) 数据库中的评级列的类型为 ENUM('G','PG','PG-13','R','NC-17') (注意破折号)。这: @Entity @Table(name = "movies") p
假设我有一个具有以下字段的域对象: private Map maxValues = new HashMap(); StatType 是一个 Java 枚举。 我如何使用 JPA 映射它? 最佳答案 另
我正在尝试在 Spring MVC 中使用 Hibernate HQL 获取实体列表。查询如下所示: SELECT m FROM MyEntity m where property =:propert
当使用 DataContractSerializer 编写一个带有如下成员的 DataContract 时: [DataMember] public PropertyId PropId { g
我读过很多关于 objective-c 中枚举类型的文章,我发现有很多方法可以定义它们。但是我没有看到正确的方法(如果有的话)来定义一个可以用 CARS.ROLLSROYCE 调用并且不能在代码中仅与
我生活在一场噩梦中,这是一场依赖噩梦;) 我正在测试一个使用 Hibernate 3 的 EJB 应用程序。 我部署它: 在 WebSphere 8(内置于 EAR 中的 EJB JAR)上,这是我想
枚举, public enum CountEnum { ONE, TWO } 实体类, @Entity public class Test { ... @Enumerated(En
所以我一直在使用 Pay Simple SDK。我收到这个错误。有谁知道如何解决这个问题? var customerPayment = new NewCustomerPayment 所以我的模型在 P
我能够存储、检索和查询具有枚举类型的实体(使用 JPA/Hibernate)。枚举字段用 @Enumerated(EnumType.STRING) 注释。 是否可以执行类似 "SELECT a FRO
我是一名优秀的程序员,十分优秀!