Spring-data-jpa storing blob

后端 未结 6 908
梦如初夏
梦如初夏 2021-02-04 14:17

What is \"best\" or canonical way to store entity with blob using spring-data-jpa?

@Entity
public class Entity {
  @Id
  private Long id;
  @Lob()
  private Blob         


        
6条回答
  •  抹茶落季
    2021-02-04 15:00

    Autowire your repository interface and call the save method passing your entity object.

    I have a similar setup which works pretty well:

    @Autowired
    Repository repository;
    
    repository.save(entity);
    
    @Entity
    @Table(name = "something")
    public class Message {
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
    
        @Lob
        @Column
        private byte[] data;
    

提交回复
热议问题