我有一个Java应用程序与Pojo是
public class ArtifactBlobs{
private static final long serialVersionUID = 1L;
private String guid;
private String workspaceId;
private Blob artifactBlobValue;
private Date createdAt;
private Long createdBy;
private Date updatedAt;
private Long updatedBy;
private Set waasArtifactsBlobsMetas = new HashSet(0);
public ArtifactsBlobs() {
}
public ArtifactsBlobs(String guid, Date createdAt, Date updatedAt) {
this.guid = guid;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}
public ArtifactsBlobs(String guid, String workspaceId,
Blob artifactBlobValue, Date createdAt, Long createdBy,
Date updatedAt, Long updatedBy) {
this.guid = guid;
this.workspaceId = workspaceId;
this.artifactBlobValue = artifactBlobValue;
this.createdAt = createdAt;
this.createdBy = createdBy;
this.updatedAt = updatedAt;
this.updatedBy = updatedBy;
}
public String getGuid() {
return this.guid;
}
public void setGuid(String guid) {
this.guid = guid;
}
public String getWorkspaceId() {
return this.workspaceId;
}
public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId;
}
public Blob getArtifactBlobValue() {
return this.artifactBlobValue;
}
@SuppressWarnings("CPD-START")
public void setArtifactBlobValue(Blob artifactBlobValue) {
this.artifactBlobValue = artifactBlobValue;
}
public Date getCreatedAt() {
return this.createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Long getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
public Date getUpdatedAt() {
return this.updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Long getUpdatedBy() {
return this.updatedBy;
}
public void setUpdatedBy(Long updatedBy) {
this.updatedBy = updatedBy;
}
public Set getWaasArtifactsBlobsMetas() {
return this.waasArtifactsBlobsMetas;
}
public void setWaasArtifactsBlobsMetas(Set waasArtifactsBlobsMetas) {
this.waasArtifactsBlobsMetas = waasArtifactsBlobsMetas;
}
}
字符串
正是这种方法失败了
private ArtifactsBlobs
getArtifactBlobById(
String workspaceId,
String blobId)
{
public static final String GET_ARTIFACT_BLOB_BY_ID = "from ArtifactsBlobs A where A.guid = :blobId and A.workspaceId = :workspaceId";
Map<String, Object> valuesMap = new HashMap<>();
valuesMap.put("workspaceId", workspaceId);
valuesMap.put("blobId", blobId);
ArtifactsBlobs artifactBlob =
iGenericDAO.getEntity(
SqlQuery.GET_ARTIFACT_BLOB_BY_ID,
valuesMap);
if (artifactBlob == null)
{
// Since the blobId is derived from data stored in artifacts table,
// absence of corr. entry in blobs table indicates data is incorrect in DB
throw new DataIntegrityViolationException(
"An unexpected error has occured while processing the request. Please try again later.");
}
return artifactBlob;
}
型
而hibernatebean配置是
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 23 Sep, 2014 12:10:11 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.db.entity.autogen.ArtifactsBlobs" table="artifacts_blobs">
<id name="guid" type="string">
<column name="id" length="36" />
<generator class="assigned" />
</id>
<property name="workspaceId" type="string">
<column name="workspace_id" length="36" />
</property>
<property name="artifactBlobValue" type="blob">
<column name="artifact_blob_value" not-null="true"/>
</property>
<property name="createdAt" type="timestamp">
<column name="created_at" length="19" not-null="true" />
</property>
<property name="createdBy" type="java.lang.Long">
<column name="created_by" />
</property>
<property name="updatedAt" type="timestamp">
<column name="updated_at" length="19" not-null="true" />
</property>
<property name="updatedBy" type="java.lang.Long">
<column name="updated_by" />
</property>
<set name="waasArtifactsBlobsMetas" table="waas_artifacts_blobs_meta" inverse="true" lazy="true" fetch="select">
<key>
<column name="blob_id" length="36" not-null="true" />
</key>
<one-to-many class="com.kony.waas.db.entity.autogen.WaasArtifactsBlobsMeta" />
</set>
</class>
</hibernate-mapping>
and the Db Structure is
CREATE TABLE artifacts_blobs (
id varchar(36) NOT NULL,
workspace_id varchar(36) NOT NULL,
artifact_blob_value bytea NOT NULL,
created_at timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_by bigint NOT NULL,
updated_at timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_by bigint NOT NULL,
PRIMARY KEY (id)
) ;
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]
1条答案
按热度按时间siv3szwd1#
您的工件blob列存储一个字节数组。在Postgresql中,这通常使用LOB定位器来管理,LOB定位器是一个long类型的ID。然后使用该ID从另一个表中检索实际的blob。所有这些都是在后台处理的,但是如果没有关于数据类型的提示,检索到的数据就不能转换为blob。
要使用注解MapArtifactBlobs类中的blob属性,请尝试以下操作:
字符串
对于clob,它是只包含文本数据的blob:
型
我不确定如何将这个注解转换成XMLMap。我建议切换到Java注解Map,因为这是一个简单的过程。