paulcwarren/spring-content

Relation "Blobs" not found

clemi2408 opened this issue · 3 comments

Hi

i am using

'org.springframework.boot' version '3.2.2'

together with

'com.github.paulcwarren:spring-content-jpa-boot-starter:3.0.9'

my repository is defined (hint: i am using javers)

@JaversSpringDataAuditable
public interface MediaTypeEntityRepository extends JpaRepository<MediaTypeEntity, Long> {}

further my store looks like this

public interface MediaEntityContentStore extends ContentStore<MediaEntity, String> {}

my entity:

public class MediaEntity implements Serializable {
   
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
   
    @ContentId
    private String mediaId;
 
    @MimeType
    private String mediaType;
 
    @OriginalFileName
    private String uploadFileName;
 
    @ContentLength
    private Long lengthInBytes;
   
    private Integer lengthInSeconds;
 
}

my spring boot application is loading entities, repos and store like this

@EnableJpaStores(basePackages = "example.store")
@EnableJpaRepositories(basePackages = "example.repository")
@EntityScan(basePackages = "example.entity")

but startup fails due to a missing "blobs" table.

org.postgresql.util.PSQLException: ERROR: relation "blobs" does not exist

Full exception:

2024-03-24T14:29:42.930+01:00 ERROR 3985 --- [           main] s.c.j.i.PostgresBlobResourceOutputStream : initializing postgres blob output stream for resource: xxxxx
 
org.postgresql.util.PSQLException: ERROR: relation "blobs" does not exist
  Position: 25
                at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2725) ~[postgresql-42.7.2.jar:42.7.2]
                at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2412) ~[postgresql-42.7.2.jar:42.7.2]
                at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:371) ~[postgresql-42.7.2.jar:42.7.2]
                at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:502) ~[postgresql-42.7.2.jar:42.7.2]
                at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:419) ~[postgresql-42.7.2.jar:42.7.2]
                at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:194) ~[postgresql-42.7.2.jar:42.7.2]
                at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:137) ~[postgresql-42.7.2.jar:42.7.2]
                at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-5.0.1.jar:na]
                at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-5.0.1.jar:na]
                at internal.org.springframework.content.jpa.io.PostgresBlobResourceOutputStream.initializeStream(PostgresBlobResourceOutputStream.java:43) ~[spring-content-jpa-3.0.9.jar:na]
                at internal.org.springframework.content.jpa.io.BlobResourceOutputStream.write(BlobResourceOutputStream.java:51) ~[spring-content-jpa-3.0.9.jar:na]
                at java.base/java.io.OutputStream.write(OutputStream.java:164) ~[na:na]
                at java.base/java.io.BufferedOutputStream.implWrite(BufferedOutputStream.java:216) ~[na:na]
                at java.base/java.io.BufferedOutputStream.write(BufferedOutputStream.java:199) ~[na:na]
                at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1488) ~[commons-io-2.15.1.jar:2.15.1]
                at org.apache.commons.io.IOUtils.copy(IOUtils.java:1107) ~[commons-io-2.15.1.jar:2.15.1]
                at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1460) ~[commons-io-2.15.1.jar:2.15.1]
                at internal.org.springframework.content.jpa.store.DefaultJpaStoreImpl.setContent(DefaultJpaStoreImpl.java:215) ~[spring-content-jpa-3.0.9.jar:na]
                at internal.org.springframework.content.commons.store.factory.StoreImpl.lambda$setContent$0(StoreImpl.java:58) ~[spring-content-commons-3.0.9.jar:na]
                at internal.org.springframework.content.commons.store.factory.StoreImpl.internalSetContent(StoreImpl.java:160) ~[spring-content-commons-3.0.9.jar:na]
                at internal.org.springframework.content.commons.store.factory.StoreImpl.setContent(StoreImpl.java:55) ~[spring-content-commons-3.0.9.jar:na]
                at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
                at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na]
                at internal.org.springframework.content.commons.store.factory.StoreMethodInterceptor.invoke(StoreMethodInterceptor.java:74) ~[spring-content-commons-3.0.9.jar:na]
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.3.jar:6.1.3]
                at internal.org.springframework.content.commons.store.factory.StoreExceptionTranslatorInterceptor.invoke(StoreExceptionTranslatorInterceptor.java:23) ~[spring-content-commons-3.0.9.jar:na]
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.3.jar:6.1.3]
                at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-6.1.3.jar:6.1.3]
                at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:385) ~[spring-tx-6.1.3.jar:6.1.3]
                at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-6.1.3.jar:6.1.3]
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.3.jar:6.1.3]
                at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:220) ~[spring-aop-6.1.3.jar:6.1.3]
                at jdk.proxy2/jdk.proxy2.$Proxy155.setContent(Unknown Source) ~[na:na]
                at it.schwarz.socialize.backend.service.DemoDataService.insertImages(DemoDataService.java:207) ~[main/:na]
 

Code leading to the error in line 207 is calling before doing repo save action:

mediaEntityContentStore.setContent(imageMediaEntity,new ByteArrayInputStream(bytes));

Did i miss to load configuration classes to get "Blob" table created?

Thanks for your Help

clem

I think you should add this part to your config:

  @Value("/org/springframework/content/jpa/schema-drop-postgresql.sql")
  private Resource dropRepositoryTables;

  @Value("/org/springframework/content/jpa/schema-postgresql.sql")
  private Resource createRepositoryTables;

  @Bean
  DataSourceInitializer datasourceInitializer() {
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();

    databasePopulator.addScript(dropRepositoryTables);
    databasePopulator.addScript(createRepositoryTables);
    databasePopulator.setIgnoreFailedDrops(true);

    DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource());
    initializer.setDatabasePopulator(databasePopulator);

    return initializer;
  }

Hi @clemi2408 ,

If you are using the spring content jpa boot starter then I would expect the db to be initialized assuming that there is a DataSource bean defined by your application (which I assume has to be the case). It's possible that Javers is messing with that eban but I doubt it (not familiar with that library).

@RuudGianesini suggestion is a workaround. But you shouldn't have to do it. I do have examples for this and they are green in CI so is there any chance you have a sample that reproduces the issue? I'm, interested in seeing what the delta is between the example and your case.

Closing due to inactivity. Please re-open if this is still an issue.