spring postgres中类型long的值错误

krcsximq  于 2023-08-02  发布在  Spring
关注(0)|答案(1)|浏览(139)

我有一个Java应用程序与Pojo是

  1. public class ArtifactBlobs{
  2. private static final long serialVersionUID = 1L;
  3. private String guid;
  4. private String workspaceId;
  5. private Blob artifactBlobValue;
  6. private Date createdAt;
  7. private Long createdBy;
  8. private Date updatedAt;
  9. private Long updatedBy;
  10. private Set waasArtifactsBlobsMetas = new HashSet(0);
  11. public ArtifactsBlobs() {
  12. }
  13. public ArtifactsBlobs(String guid, Date createdAt, Date updatedAt) {
  14. this.guid = guid;
  15. this.createdAt = createdAt;
  16. this.updatedAt = updatedAt;
  17. }
  18. public ArtifactsBlobs(String guid, String workspaceId,
  19. Blob artifactBlobValue, Date createdAt, Long createdBy,
  20. Date updatedAt, Long updatedBy) {
  21. this.guid = guid;
  22. this.workspaceId = workspaceId;
  23. this.artifactBlobValue = artifactBlobValue;
  24. this.createdAt = createdAt;
  25. this.createdBy = createdBy;
  26. this.updatedAt = updatedAt;
  27. this.updatedBy = updatedBy;
  28. }
  29. public String getGuid() {
  30. return this.guid;
  31. }
  32. public void setGuid(String guid) {
  33. this.guid = guid;
  34. }
  35. public String getWorkspaceId() {
  36. return this.workspaceId;
  37. }
  38. public void setWorkspaceId(String workspaceId) {
  39. this.workspaceId = workspaceId;
  40. }
  41. public Blob getArtifactBlobValue() {
  42. return this.artifactBlobValue;
  43. }
  44. @SuppressWarnings("CPD-START")
  45. public void setArtifactBlobValue(Blob artifactBlobValue) {
  46. this.artifactBlobValue = artifactBlobValue;
  47. }
  48. public Date getCreatedAt() {
  49. return this.createdAt;
  50. }
  51. public void setCreatedAt(Date createdAt) {
  52. this.createdAt = createdAt;
  53. }
  54. public Long getCreatedBy() {
  55. return this.createdBy;
  56. }
  57. public void setCreatedBy(Long createdBy) {
  58. this.createdBy = createdBy;
  59. }
  60. public Date getUpdatedAt() {
  61. return this.updatedAt;
  62. }
  63. public void setUpdatedAt(Date updatedAt) {
  64. this.updatedAt = updatedAt;
  65. }
  66. public Long getUpdatedBy() {
  67. return this.updatedBy;
  68. }
  69. public void setUpdatedBy(Long updatedBy) {
  70. this.updatedBy = updatedBy;
  71. }
  72. public Set getWaasArtifactsBlobsMetas() {
  73. return this.waasArtifactsBlobsMetas;
  74. }
  75. public void setWaasArtifactsBlobsMetas(Set waasArtifactsBlobsMetas) {
  76. this.waasArtifactsBlobsMetas = waasArtifactsBlobsMetas;
  77. }
  78. }

字符串
正是这种方法失败了

  1. private ArtifactsBlobs
  2. getArtifactBlobById(
  3. String workspaceId,
  4. String blobId)
  5. {
  6. public static final String GET_ARTIFACT_BLOB_BY_ID = "from ArtifactsBlobs A where A.guid = :blobId and A.workspaceId = :workspaceId";
  7. Map<String, Object> valuesMap = new HashMap<>();
  8. valuesMap.put("workspaceId", workspaceId);
  9. valuesMap.put("blobId", blobId);
  10. ArtifactsBlobs artifactBlob =
  11. iGenericDAO.getEntity(
  12. SqlQuery.GET_ARTIFACT_BLOB_BY_ID,
  13. valuesMap);
  14. if (artifactBlob == null)
  15. {
  16. // Since the blobId is derived from data stored in artifacts table,
  17. // absence of corr. entry in blobs table indicates data is incorrect in DB
  18. throw new DataIntegrityViolationException(
  19. "An unexpected error has occured while processing the request. Please try again later.");
  20. }
  21. return artifactBlob;
  22. }


而hibernatebean配置是

  1. <?xml version="1.0"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  3. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  4. <!-- Generated 23 Sep, 2014 12:10:11 PM by Hibernate Tools 3.4.0.CR1 -->
  5. <hibernate-mapping>
  6. <class name="com.db.entity.autogen.ArtifactsBlobs" table="artifacts_blobs">
  7. <id name="guid" type="string">
  8. <column name="id" length="36" />
  9. <generator class="assigned" />
  10. </id>
  11. <property name="workspaceId" type="string">
  12. <column name="workspace_id" length="36" />
  13. </property>
  14. <property name="artifactBlobValue" type="blob">
  15. <column name="artifact_blob_value" not-null="true"/>
  16. </property>
  17. <property name="createdAt" type="timestamp">
  18. <column name="created_at" length="19" not-null="true" />
  19. </property>
  20. <property name="createdBy" type="java.lang.Long">
  21. <column name="created_by" />
  22. </property>
  23. <property name="updatedAt" type="timestamp">
  24. <column name="updated_at" length="19" not-null="true" />
  25. </property>
  26. <property name="updatedBy" type="java.lang.Long">
  27. <column name="updated_by" />
  28. </property>
  29. <set name="waasArtifactsBlobsMetas" table="waas_artifacts_blobs_meta" inverse="true" lazy="true" fetch="select">
  30. <key>
  31. <column name="blob_id" length="36" not-null="true" />
  32. </key>
  33. <one-to-many class="com.kony.waas.db.entity.autogen.WaasArtifactsBlobsMeta" />
  34. </set>
  35. </class>
  36. </hibernate-mapping>
  37. and the Db Structure is
  38. CREATE TABLE artifacts_blobs (
  39. id varchar(36) NOT NULL,
  40. workspace_id varchar(36) NOT NULL,
  41. artifact_blob_value bytea NOT NULL,
  42. created_at timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  43. created_by bigint NOT NULL,
  44. updated_at timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  45. updated_by bigint NOT NULL,
  46. PRIMARY KEY (id)
  47. ) ;
  48. The saving of the POJO class is going fine but while retrieving I am facing this error


javax.persistence.PersistenceException: org.hibernate.exception.DataException:无法在org. hibernate. internal. ExceptionConverterImpl. convert(ExceptionConverterImpl.java:154)~[hibernate-core-5.3.20.Final.jar:5.3.20.Final] at org. hibernate. query. internal. AbstractProducedQuery.java:1575)~[hibernate-core-5.3.20.Final.jar:5.3.20.Final] at org. hibernate. internal. AbstractProducedQuery. uniqueResult(AbstractProducedQuery.java:1608)~[hibernate-core-5.3.20.Final.jar:5.3.20.Final]
原因:org. postgresql. util. PSQLExException:类型long的值错误:\x353131623738383964356139323839376136383032663366633032366339643663633239383936383566361303932316362353835626661643661636430393066336563356131623337 34313638353539303335343662306336666164343232353362 306261306在org。postgresql jdbc. PgResultSet。toLong(PgResultSet.java:3253)~[postgresql-42.5.0.jar:42.5.0] at org. postgresql jdbc. PgResultSet。getLong(PgResultSet.java:2436)~[postgresql-42.5.0.jar:42.5.0] at org. postgresql jdbc. PgResultSet。getBlob(PgResultSet.java:456)~[postgresql-42.5.0.jar:42.5.0] at org. postgresql jdbc. PgResultSet。getBlob(PgResultSet.java:442)~[postgresql-42.5.0.jar:42.5.0]

siv3szwd

siv3szwd1#

您的工件blob列存储一个字节数组。在Postgresql中,这通常使用LOB定位器来管理,LOB定位器是一个long类型的ID。然后使用该ID从另一个表中检索实际的blob。所有这些都是在后台处理的,但是如果没有关于数据类型的提示,检索到的数据就不能转换为blob。
要使用注解MapArtifactBlobs类中的blob属性,请尝试以下操作:

  1. @Lob
  2. @Type(type = "org.hibernate.type.BinaryType")
  3. private Blob artifactBlobValue;

字符串
对于clob,它是只包含文本数据的blob:

  1. @Type(type = "org.hibernate.type.TextType")


我不确定如何将这个注解转换成XMLMap。我建议切换到Java注解Map,因为这是一个简单的过程。

相关问题