Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate Subselect Entity not supported by EntityMetamodelImpl #519

Closed
jwgmeligmeyling opened this issue Feb 24, 2018 · 1 comment
Closed

Comments

@jwgmeligmeyling
Copy link
Collaborator

Description

After playing a bit with table functions (see also #181), I had the idea to experiment with mapping a generate_series query to an entity using the @Subselect annotation. Find below the produced stack trace.

A trivial work around is to wrap the query into to a view and map that instead. I am uncertain whether a fix for this is worthwhile, but it could perhaps be a step towards implementing table functions (#181).

package com.pallasathenagroup.entities.series;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Subselect;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.time.LocalDateTime;

@Data
@Entity
@Immutable
@Subselect("select start_date_time, start_date_time + interval '1 year' as end_date_time " +
    "from generate_series('2016-09-01'::timestamp, date_trunc('year', now()) + interval '8 months', '1 year') as start_date_time")
@EqualsAndHashCode(of = {"start"})
public class CollegeYearSeries implements Comparable<CollegeYearSeries> {

    @Id
    @Column(name = "start_date_time")
    private LocalDateTime start;

    @Column(name = "end_date_time")
    private LocalDateTime end;

    @Override
    public int compareTo(CollegeYearSeries o) {
        return getStart().compareTo(o.getStart());
    }
}
Caused by: java.lang.NullPointerException
	at com.blazebit.persistence.impl.hibernate.HibernateExtendedQuerySupport.getColumnTypes(HibernateExtendedQuerySupport.java:246)
	at com.blazebit.persistence.impl.EntityMetamodelImpl.<init>(EntityMetamodelImpl.java:110)
	at com.blazebit.persistence.impl.CriteriaBuilderFactoryImpl.<init>(CriteriaBuilderFactoryImpl.java:81)
	at com.blazebit.persistence.impl.CriteriaBuilderConfigurationImpl.createCriteriaBuilderFactory(CriteriaBuilderConfigurationImpl.java:599)
	at com.pallasathenagroup.iris.producers.CriteriaBuilderFactoryProducer.init(CriteriaBuilderFactoryProducer.java:32)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:114)
	at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:103)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
	at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
	at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:53)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:107)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.as.weld.ejb.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:100)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
	at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
	... 29 more

Expected behavior

Actual behavior

Steps to reproduce

Environment

Version: 1.2.0.Alpha3
JPA-Provider: Hibernate 5.2.12
DBMS: PostgresSQL
Application Server: Wildfly

@beikov
Copy link
Member

beikov commented Feb 24, 2018

Hmm, this seems like a bug that should be fixed. Have to investigate what is happening here exactly.
Implementing generate_series and table functions in general is going to require the use of the SQL from clause replacement mechanism since a table function will most probably have parameters.

@beikov beikov self-assigned this Feb 24, 2018
jwgmeligmeyling added a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 1, 2018
jwgmeligmeyling added a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 3, 2018
jwgmeligmeyling added a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 3, 2018
jwgmeligmeyling added a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 3, 2018
jwgmeligmeyling added a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 3, 2018
jwgmeligmeyling added a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 3, 2018
beikov pushed a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 11, 2018
beikov pushed a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 11, 2018
beikov added a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 11, 2018
beikov pushed a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 11, 2018
beikov pushed a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 11, 2018
beikov added a commit to jwgmeligmeyling/blaze-persistence that referenced this issue Mar 11, 2018
beikov pushed a commit that referenced this issue Mar 11, 2018
@beikov beikov closed this as completed in a80a939 Mar 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants