gpt4 book ai didi

java - hibernate 空间 : Type org. hibernatespatial.GeometryUserType

转载 作者:行者123 更新时间:2023-11-30 09:33:35 31 4
gpt4 key购买 nike

我使用的是 Hibernate Spatial 版本 4.0-M1。我正在学习教程 here .但是,我的代码失败并出现以下错误:org.hibernate.MappingException: Could not determine type for: org.hibernatespatial.GeometryUserType, at #table_name# for column #geometry_column#

我的 session 工厂创建类如下图所示:

public class HibernateUtil {
private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Exception ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}

在寻找可能的原因后,我发现它与我的配置有关。我的hibernate.cfg.xml如下图:

<session-factory>

<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/dbName</property>
<property name="connection.username">dbUsername</property>
<property name="connection.password">dbPassword</property>

<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernatespatial.postgis.PostgisDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<property name="show_sql">true</property>

<mapping class="com.testapp.model.EntityClassWithAnnotations" />

</session-factory>

任何关于我可能做错的想法将不胜感激。

更新:我的实体类如下所示:

@Entity
@Table(name = "table_name")
public class MyEntityClass implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
@Column(name = "gid")
private Long gid;

@Column(name = "adm1_name")
private String adminName;

@Column(name = "adm1_code")
private String adminCode;

@Column(name = "pmal")
private Double pmale;

@Column(name = "pfem")
private Double pfemale;

@Type(type = "org.hibernatespatial.GeometryUserType")
@Column(name = "the_geom", nullable = true)
private Geometry geom;

public MyEntityClass() {}

public Long getGid() {
return gid;
}

public void setGid(Long gid) {
this.gid = gid;
}

public String getAdminName() {
return adminName;
}

public void setAdmin_name(String adminName) {
this.adminName = adminName;
}

public String getAdminCode() {
return adminCode;
}

public void setAdmin_code(String adminCode) {
this.adminCode = adminCode;
}

public Double getPmale() {
return pmale;
}

public void setPmale(Double pmale) {
this.pmale = pmale;
}

public Double getPfemale() {
return pfemale;
}

public void setPfemale(Double pfemale) {
this.pfemale = pfemale;
}

public Geometry getGeom() {
return geom;
}

public void setGeom(Geometry geom) {
this.geom = geom;
}
}

最佳答案

已编辑:我想我在您的 hibernate.cfg 文件中看到了错误,您使用了错误的方言。

将方言行替换为:

<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>

关于java - hibernate 空间 : Type org. hibernatespatial.GeometryUserType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12086586/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com