来自两个表的数据的Jpa Join查询,org.hibernate.MappingException:没有JDBC类型的方言映射:2002
我有这个结构 汽车品牌来自两个表的数据的Jpa Join查询,org.hibernate.MappingException:没有JDBC类型的方言映射:2002,hibernate,jpa,Hibernate,Jpa,我有这个结构 汽车品牌 @Entity @Getter @Setter public class VehicleBrand { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private String otherInfo; } 车辆模型 @Entity @Getter @Setter public class
@Entity
@Getter
@Setter
public class VehicleBrand {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String otherInfo;
}
车辆模型
@Entity
@Getter
@Setter
public class VehicleModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
private VehicleBrand brand;
private String name;
private String otherInfo;
}
我还想使用Dto对象,因为我想得到一个连接查询,该查询将从两个表返回数据
模型
@Getter
@Setter
public class ModelDto {
private Long id;
private String name;
private long brand_id;
}
@Getter
@Setter
public class VehicleBrandModelDto {
private Long id;
private String name;
List<ModelDto> model;
}
任何关于我如何实现这一目标的建议,或者这可能是不可能的
数据库属性
spring.datasource.url=jdbc:postgresql://changed.compute-1.amazonaws.com:5432/changed
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=false
spring.datasource.username=changed
spring.datasource.password=changed
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.connection.pool_size=17
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driverClassName=org.postgresql.Driver
DB version postgress 12不确定为什么会出现这样的问题:JDBC type:2002没有方言映射。你能把整个stacktrace都寄出去吗?这通常建议您使用的SQL类型在方言中没有为其注册匹配的Hibernate类型。类型代码2002引用了
STRUCT
类型,但您发布的模型不包含任何外来类型。我猜VehicleModel
还有一些其他属性使用了未正确注册的类型。能否显示车辆模型的完整映射
你可能也喜欢你所能提供的
我创建了这个库,以便在JPA模型和自定义接口或抽象类定义的模型之间进行简单的映射,类似于类固醇上的Spring数据投影。其思想是以您喜欢的方式定义目标结构(域模型),并通过JPQL表达式将属性(getter)映射到实体模型
在Blaze持久性实体视图中,您的用例的DTO模型可能如下所示:
@EntityView(VehicleBrand.class)
public interface VehicleBrandModelDto {
@IdMapping
Long getId();
String getName();
// Use this if you have an inverse one-to-many
@Mapping("models")
// Otherwise you can also do ad-hoc joins
// @Mapping("VehicleModel[brand.id = VIEW(id)]")
List<ModelDto> getModel();
@EntityView(VehicleModel.class)
interface ModelDto {
@IdMapping
Long getId();
String getName();
@Mapping("brand.id")
long getBrandId();
}
}
你用什么hibernate方言?我用的是postgres@sternkt hibernate有很多postgres方言?你使用的是什么方言?你有什么版本的postgres?我已经在上面的db properties@SternK发布了PostgreSql10方言
是postgres db的最新hibernate方言,所以在你的案例中这是一个正确的选择。
org.springframework.orm.jpa.JpaSystemException: No Dialect mapping for JDBC type: 2002; nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002
spring.datasource.url=jdbc:postgresql://changed.compute-1.amazonaws.com:5432/changed
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=false
spring.datasource.username=changed
spring.datasource.password=changed
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.connection.pool_size=17
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driverClassName=org.postgresql.Driver
@EntityView(VehicleBrand.class)
public interface VehicleBrandModelDto {
@IdMapping
Long getId();
String getName();
// Use this if you have an inverse one-to-many
@Mapping("models")
// Otherwise you can also do ad-hoc joins
// @Mapping("VehicleModel[brand.id = VIEW(id)]")
List<ModelDto> getModel();
@EntityView(VehicleModel.class)
interface ModelDto {
@IdMapping
Long getId();
String getName();
@Mapping("brand.id")
long getBrandId();
}
}
List<VehicleBrandModelDto> findAll();