1

のために動作しません。私は、単純なエンティティに持っているあなたは、私はネイティブの名前付きクエリによってのために、結果として、POJOを使用し、それを使用したい見ることができるように@SqlResultSetMapping @ConstructorResult @ColumnResult java.time.LocalDate

@Entity 
@NamedNativeQueries({ 
    @NamedNativeQuery(name = "Account.dailyRegistered", 
     query = "select date(date_trunc('day', creation_date)) as period, count(1) as metric" 
      + " from account " 
      + "group by period " 
      + "order by period", 
     resultSetMapping = "PeriodMetric.byDay") 
}) 
@SqlResultSetMappings({ 
    @SqlResultSetMapping(
     name = "PeriodMetric.byDay", 
     classes = { 
      @ConstructorResult(
       targetClass = PeriodMetric.class, 
       columns = { 
        @ColumnResult(name = "period", type = java.time.LocalDate.class), 
        @ColumnResult(name = "metric", type = Integer.class) 
       } 
      ) 
     } 
    ) 
}) 
public class Account {...} 



public class PeriodMetric { 
    private LocalDate period; 
    private Integer metric; 

    public PeriodMetric(LocalDate period, Integer metric) { 
     ... 
    } 
    ... 
} 

public interface AccountRepository extends JpaRepository<Account, Long> { 
    @Query(name = "Account.dailyRegistered", nativeQuery = true) 
    List<PeriodMetric> findDailyRegistered(); 
} 

SpringのJPAリポジトリにあります。 私はリポジトリメソッドを呼び出すと、私は次の例外を取得:

Caused by: org.hibernate.type.SerializationException: could not deserialize 
    at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:243) 
    at org.hibernate.internal.util.SerializationHelper.deserialize(SerializationHelper.java:287) 
    at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:138) 
    at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:113) 
    at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:27) 
    at org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:60) 
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) 
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:235) 
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:231) 
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:227) 
    at org.hibernate.loader.custom.ScalarResultColumnProcessor.extract(ScalarResultColumnProcessor.java:54) 
    at org.hibernate.loader.custom.ConstructorResultColumnProcessor.extract(ConstructorResultColumnProcessor.java:58) 
    at org.hibernate.loader.custom.ResultRowProcessor.buildResultRow(ResultRowProcessor.java:83) 
    at org.hibernate.loader.custom.ResultRowProcessor.buildResultRow(ResultRowProcessor.java:60) 
    at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:414) 
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:756) 
    at org.hibernate.loader.Loader.processResultSet(Loader.java:972) 
    at org.hibernate.loader.Loader.doQuery(Loader.java:930) 
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) 
    at org.hibernate.loader.Loader.doList(Loader.java:2610) 
    at org.hibernate.loader.Loader.doList(Loader.java:2593) 
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422) 
    at org.hibernate.loader.Loader.list(Loader.java:2417) 
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:336) 
    at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1980) 
    at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322) 
    at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125) 
    at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606) 
    at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:529) 
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:206) 
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78) 
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:100) 
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:91) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:462) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) 
    ... 7 more 
Caused by: java.io.StreamCorruptedException: invalid stream header: 32303136 
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:806) 
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299) 
    at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:309) 
    at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:299) 
    at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:218) 
    ... 49 more 

私は何も助けない設定でプレイするために一日を過ごします。私が間違っていることは何ですか?

ところで、

それはこのhttp://www.thoughts-on-java.org/result-set-mapping-constructor-result-mappings/ような記事をもとに簡単なものでなければなりません。

私はSpring Data JPA 1.9.5.RELEASE、Hibernate 5.1.0.Final、Hibernate-Jpa-api 2.1を使用します。

@EntityScanにJsr310JpaConvertersが追加されました。私は私の場合には、Hibernateがjava.time.LocalDateを参照してorg.hibernate.type.SerializableTypeを使用し、LOCALDATEに結果値をデシリアライズできなかったが、他の例のために、Hibernateはを使用していることに気づいたデバッグ後

org.hibernate.type.DateTypeはjava.time.LocalDateを参照しており、これらのケースで機能します(ネイティブクエリーという名前ではありません)。

+0

例えば私がLocalDateを文字列で置き換えると、この設定が機能します。 –

答えて

関連する問題