解决方案似乎如下:
@Column使用JPA批注将字段映射到所需的列,
@Type以使用方言指定Hibernate映射。
@Column(columnDefinition = "Geometry", nullable = true) @Type(type = "org.hibernate.spatial.GeometryType")public Point centerPoint;
您可以在hibernate.cfg.xml文件中添加Hibernate属性,以查看db请求,并尝试使用基于文本的编辑器(例如Notepad ++,带有“UTF-8” /“ ANSI” /“其他字符集”)捕获字符串编码的问题。
<!--hibernate.cfg.xml --><property name="show_sql">true</property><property name="format_sql">true</property><property name="use_sql_comments">true</property>
要添加hibernate属性,您将拥有一个hibernate.cfg.xml文件,其中包含以下内容。不要复制/粘贴它,因为它是面向MySQL的。只需看看我在前面插入的属性的位置即可。
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory><property name="hibernate.bytepre.use_reflection_optimizer">true</property><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.connection.password">db-password</property><property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db-name</property><property name="hibernate.connection.username">db-username</property><property name="hibernate.default_entity_mode">pojo</property><property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property><property name="hibernate.format_sql">true</property><property name="hibernate.search.autoregister_listeners">false</property>**<property name="hibernate.show_sql">true</property>**<property name="hibernate.use_sql_comments">false</property><mapping ressource="...." /><!-- other hbm.xml mappings below... --> </session-factory> </hibernate-configuration>
记录所有sql的另一种方法是在log4j.properties文件内添加特定于包的属性:
log4j.logger.org.hibernate.SQL=DEBUGlog4j.logger.org.hibernate.type=TRACE
祝好运!



