Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何注册同时处理real[]和text[]数组列类型的自定义Hibernate数组类型_Java_Arrays_Hibernate_Spring Data Jpa_Hibernate Types - Fatal编程技术网

Java 如何注册同时处理real[]和text[]数组列类型的自定义Hibernate数组类型

Java 如何注册同时处理real[]和text[]数组列类型的自定义Hibernate数组类型,java,arrays,hibernate,spring-data-jpa,hibernate-types,Java,Arrays,Hibernate,Spring Data Jpa,Hibernate Types,我正在使用库来定制Hibernate类型 我有两个CustomArrayType来处理real[]和text[]数组类型 我可以用Hibernate方言注册一个CustomStringArrayType(例如PostgreSQL94方言),但是如何注册两个类型呢 下面是我的自定义方言,如果没有它,我将获得2003年未找到的方言错误: public class HibernateCustomDialect extends org.hibernate.dialect.PostgreSQL94Dial

我正在使用库来定制Hibernate类型

我有两个
CustomArrayType
来处理
real[]
text[]
数组类型

我可以用Hibernate方言注册一个
CustomStringArrayType
(例如
PostgreSQL94方言
),但是如何注册两个类型呢

下面是我的自定义方言,如果没有它,我将获得2003年未找到的方言错误:

public class HibernateCustomDialect extends org.hibernate.dialect.PostgreSQL94Dialect {
    private static final Logger log = LoggerFactory.getLogger(HibernateCustomDialect.class);


    public HibernateCustomDialect() {
        super();
        log.info("Registering Custom Hibernate Dialect - {}", HibernateCustomDialect.class.getName());
        this.registerHibernateType(Types.ARRAY, CustomStringArrayType.class.getName());
    }
}

CustomStringArrayType
不是来自项目。您可以使用,它更通用,应该处理
real[]
text[]
,同时允许您在Java端使用
列表

@Entity(name = "Event")
@Table(name = "event")
@TypeDef(
    name = "list-array",
    typeClass = ListArrayType.class
)
public class Event {
 
    @Id
    private Long id;
 
    @Type(type = "list-array")
    @Column(
        name = "sensor_ids",
        columnDefinition = "uuid[]"
    )
    private List<UUID> sensorIds;
 
    @Type(type = "list-array")
    @Column(
        name = "sensor_names",
        columnDefinition = "text[]"
    )
    private List<String> sensorNames;
 
    @Type(type = "list-array")
    @Column(
        name = "sensor_values",
        columnDefinition = "integer[]"
    )
    private List<Integer> sensorValues;
 
    @Type(type = "list-array")
    @Column(
        name = "sensor_long_values",
        columnDefinition = "bigint[]"
    )
    private List<Long> sensorLongValues;
 
    @Type(
        type = "com.vladmihalcea.hibernate.type.array.ListArrayType",
        parameters = {
            @Parameter(
                name = ListArrayType.SQL_ARRAY_TYPE,
                value = "sensor_state"
            )
        }
    )
    @Column(
        name = "sensor_states",
        columnDefinition = "sensor_state[]"
    )
    private List<SensorState> sensorStates;
 
    @Type(type = "list-array")
    @Column(
        name = "date_values",
        columnDefinition = "date[]"
    )
    private List<Date> dateValues;
 
    @Type(type = "list-array")
    @Column(
        name = "timestamp_values",
        columnDefinition = "timestamp[]"
    )
    private List<Date> timestampValues;
 
    //Getters and setters omitted for brevity
}
@实体(name=“事件”)
@表(name=“事件”)
@类型定义(
name=“列表数组”,
typeClass=ListArrayType.class
)
公开课活动{
@身份证
私人长id;
@类型(Type=“列表数组”)
@纵队(
name=“传感器标识”,
columnDefinition=“uuid[]”
)
私有列表传感器;
@类型(Type=“列表数组”)
@纵队(
name=“传感器名称”,
columnDefinition=“text[]”
)
私人名单;
@类型(Type=“列表数组”)
@纵队(
name=“传感器值”,
columnDefinition=“整数[]”
)
私有价值观;
@类型(Type=“列表数组”)
@纵队(
name=“传感器长度值”,
columnDefinition=“bigint[]”
)
私人价值观;
@类型(
type=“com.vladmin.hibernate.type.array.ListArrayType”,
参数={
@参数(
name=ListArrayType.SQL\u数组\u类型,
value=“传感器状态”
)
}
)
@纵队(
name=“传感器状态”,
columnDefinition=“传感器状态[]”
)
私人国家名单;
@类型(Type=“列表数组”)
@纵队(
name=“日期值”,
columnDefinition=“日期[]”
)
私有列表值;
@类型(Type=“列表数组”)
@纵队(
name=“timestamp\u值”,
columnDefinition=“时间戳[]”
)
私有列表值;
//为简洁起见省略了getter和setter
}