ProgramingTip

JPA, Mysql Blob이 너무 긴 데이터를 반환 함

bestdevel 2021. 1. 10. 22:56
반응형

JPA, Mysql Blob이 너무 긴 데이터를 반환 함


byte[]내 엔터티에 몇 가지 필드가 있습니다. 예 :

@Entity
public class ServicePicture implements Serializable {
    private static final long serialVersionUID = 2877629751219730559L;
    // seam-gen attributes (you should probably edit these)
    @Id
    @GeneratedValue
    private Long id;
    private String description;

    @Lob
    @Basic(fetch = FetchType.LAZY)
    private byte[] picture;

내 데이터베이스 스키마에서 필드가로 설정되어 BLOB있으므로 괜찮습니다. 어쨌든 : 나는 사진이나 PDF로 삽입 할 때 매번-보다 큰 아무것도 1mb, 나는 단지이받을

16:52:27,327 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: 22001
16:52:27,327 ERROR [JDBCExceptionReporter] Data truncation: Data too long for column 'picture' at row 1
16:52:27,328 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not insert: [de.ac.dmg.productfinder.entity.ServicePicture]
16:52:27,328 ERROR [STDERR]     at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
16:52:27,328 ERROR [STDERR]     at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
16:52:27,328 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
16:52:27,328 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
16:52:27,328 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
16:52:27,328 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Unknown Source)
16:52:27,328 ERROR [STDERR]     at org.jboss.seam.persistence.EntityManagerInvocationHandler.invoke(EntityManagerInvocationHandler.java:46)
16:52:27,328 ERROR [STDERR]     at $Proxy142.persist(Unknown Source)

MySQL cnf를 선택하신 max_allowed다고 변수가 다음 과 같이 설정되어 있습니다. 16M뭔가 누락 되었습니까?


그것은 모두 열에 사용되는 열 유형에 따라 달라집니다 picture. 필요에 따라 다음을 사용하십시오.

  • TINYBLOB: 최대 길이 255 바이트
  • BLOB: 최대 길이 65,535 바이트
  • MEDIUMBLOB: 최대 길이 16,777,215 바이트
  • LONGBLOB: 최대 길이 4,294,967,295 바이트

JPA 주석에서 테이블을 생성하는 경우 다음 length과 같이 속성을 지정하여 MySQL에서 사용할 수있는 유형을 "제어"할 수 있습니다 Column.

@Lob @Basic(fetch = FetchType.LAZY)
@Column(length=100000)
private byte[] picture;

에 따라 다음을 length얻을 수 있습니다.

       0 < length <=      255  -->  `TINYBLOB`
     255 < length <=    65535  -->  `BLOB`
   65535 < length <= 16777215  -->  `MEDIUMBLOB`
16777215 < length <=    2³¹-1  -->  `LONGBLOB`

우리의 경우 다음 구문을 찾았습니다.

public class CcpArchive
{
    ...
    private byte[] ccpImage;
    ...
    @Lob
    @Column(nullable = false, name = "CCP_IMAGE", columnDefinition="BINARY(500000)")
    public byte[] getCcpImage()
    {
        return ccpImage;
    }
    ...
}

참조 URL : https://stackoverflow.com/questions/3503841/jpa-mysql-blob-returns-data-too-long

반응형