ReadAllQuery fails in checkPrepare due to NullPointerException

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

ReadAllQuery fails in checkPrepare due to NullPointerException

unimatrix-0 webmaster

Dear all,

I have a problem with schema based multitenancy:

I am developing a multitenancy enabled application. The multitenancy is schema based. Frameworks used so far are eclipselink 2.7.5, Spring data jpa 2.2.0.RELEASE and PostgreSQL. Creating, finding and deleting single entities works fine so far. A simple "findAll" works as well. However I have a problem with custom repository methods.

One entity is defined like this:

@Entity
@Table(name = "HISTORY")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type = TenantTableDiscriminatorType.SCHEMA, contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
@IdClass(SimpleLongId.class)
public class History implements Serializable {
    @Id
    @TableGenerator(name = "TABLE_GEN_HIST",
            table = "SEQUENCE_TABLE",
            pkColumnName = "SEQ_NAME",
            valueColumnName = "SEQ_COUNT",
            pkColumnValue = "HIST_SEQ")
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;

    @Column(nullable = false)
    Long fkParentId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date lastrun;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date startDateTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date endDateTime;

    @Column
    private String status;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date modified;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date created;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "history", cascade = CascadeType.ALL)
    @JoinColumns({
            @JoinColumn(name = "HISTORY_ID", referencedColumnName = "HISTORY_ID", nullable = false)})
    @CascadeOnDelete
    List<HistoryRecord> entries;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getLastrun() {
        return lastrun;
    }

    public void setLastrun(Date lastrun) {
        this.lastrun = lastrun;
    }

    public Date getStartDateTime() {
        return startDateTime;
    }

    public void setStartDateTime(Date startDateTime) {
        this.startDateTime = startDateTime;
    }

    public Date getEndDateTime() {
        return endDateTime;
    }

    public void setEndDateTime(Date endDateTime) {
        this.endDateTime = endDateTime;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public List<HistoryRecord> getEntries() {
        return entries;
    }

    public void setEntries(List<HistoryRecord> entries) {
        this.entries = entries;
    }

    public Long getFkParentId() {
        return fkParentId;
    }

    public void setFkParentId(Long fkParentId) {
        this.fkParentId = fkParentId;
    }

    @PrePersist
    public void prePersist() {
        Date now = new Date();
        created = now;
        modified = now;
    }

    @PreUpdate
    public void preUpdate() {
        modified = new Date();
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("id: ").append(getId());
        sb.append(", parentId: ").append(getFkParentId());
        sb.append(", created: ").append(getCreated());
        sb.append(", modified: ").append(getModified());
        sb.append(", startDateTime: ").append(getStartDateTime());
        sb.append(", endDateTime: ").append(getEndDateTime());
        sb.append(", Status: ").append(getStatus());
        return sb.toString();
    }
}

As I want to be able to find all History entities by the field fkParentId I created an additional method in the repository:

    @Query(value = "SELECT h FROM History h WHERE h.fkParentId = :fkParentId", nativeQuery = true)
    public List<History> findAllByFkParentId(@Param("fkParentId") Long fkParentId);

Regardles if I simply use only the method name or add the Query annotation I end up with the following stacktrace:

[EL Finest]: query: 2019-12-04 16:23:16.73--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Execute query ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
[EL Warning]: 2019-12-04 16:23:16.741--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Local Exception Stack: 
Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.QueryException
Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.NullPointerException].
Internal Exception: java.lang.NullPointerException
Query: ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
    at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1598)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:692)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:968)
...
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.NullPointerException
    at org.eclipse.persistence.internal.helper.NonSynchronizedVector.addAll(NonSynchronizedVector.java:315)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.getSelectionFields(ObjectLevelReadQuery.java:1808)
...

Debugging to the place where the exception is thrown shows me that in the RelationalDescriptor which appears to be used for the "getAllSelectionFields" the property allSelectionFields is null which causes the NullpointerException.

How can solve this? Is there something missing in the annotated entity class?

Many thanks in advance!

P.S.: I posted this question as well on stackoverflow, I hope it is OK reposting it to this user mailing list.


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ReadAllQuery fails in checkPrepare due to NullPointerException

christopher delahunt
I hit this and have a fix locally, but haven’t gotten around to checking bugzilla and submitting a patch. There are a few other issues with schema per tenant I’m looking into (sequencing with inheritance) as well.

If you file it, I can upload the changes I have and see it fixes it for you.



On Dec 13, 2019, at 5:32 AM, unimatrix-0 webmaster <[hidden email]> wrote:

Dear all,

I have a problem with schema based multitenancy:

I am developing a multitenancy enabled application. The multitenancy is schema based. Frameworks used so far are eclipselink 2.7.5, Spring data jpa 2.2.0.RELEASE and PostgreSQL. Creating, finding and deleting single entities works fine so far. A simple "findAll" works as well. However I have a problem with custom repository methods.

One entity is defined like this:

@Entity
@Table(name = "HISTORY")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type = TenantTableDiscriminatorType.SCHEMA, contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
@IdClass(SimpleLongId.class)
public class History implements Serializable {
    @Id
    @TableGenerator(name = "TABLE_GEN_HIST",
            table = "SEQUENCE_TABLE",
            pkColumnName = "SEQ_NAME",
            valueColumnName = "SEQ_COUNT",
            pkColumnValue = "HIST_SEQ")
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;

    @Column(nullable = false)
    Long fkParentId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date lastrun;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date startDateTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date endDateTime;

    @Column
    private String status;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date modified;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date created;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "history", cascade = CascadeType.ALL)
    @JoinColumns({
            @JoinColumn(name = "HISTORY_ID", referencedColumnName = "HISTORY_ID", nullable = false)})
    @CascadeOnDelete
    List<HistoryRecord> entries;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getLastrun() {
        return lastrun;
    }

    public void setLastrun(Date lastrun) {
        this.lastrun = lastrun;
    }

    public Date getStartDateTime() {
        return startDateTime;
    }

    public void setStartDateTime(Date startDateTime) {
        this.startDateTime = startDateTime;
    }

    public Date getEndDateTime() {
        return endDateTime;
    }

    public void setEndDateTime(Date endDateTime) {
        this.endDateTime = endDateTime;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public List<HistoryRecord> getEntries() {
        return entries;
    }

    public void setEntries(List<HistoryRecord> entries) {
        this.entries = entries;
    }

    public Long getFkParentId() {
        return fkParentId;
    }

    public void setFkParentId(Long fkParentId) {
        this.fkParentId = fkParentId;
    }

    @PrePersist
    public void prePersist() {
        Date now = new Date();
        created = now;
        modified = now;
    }

    @PreUpdate
    public void preUpdate() {
        modified = new Date();
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("id: ").append(getId());
        sb.append(", parentId: ").append(getFkParentId());
        sb.append(", created: ").append(getCreated());
        sb.append(", modified: ").append(getModified());
        sb.append(", startDateTime: ").append(getStartDateTime());
        sb.append(", endDateTime: ").append(getEndDateTime());
        sb.append(", Status: ").append(getStatus());
        return sb.toString();
    }
}

As I want to be able to find all History entities by the field fkParentId I created an additional method in the repository:

    @Query(value = "SELECT h FROM History h WHERE h.fkParentId = :fkParentId", nativeQuery = true)
    public List<History> findAllByFkParentId(@Param("fkParentId") Long fkParentId);

Regardles if I simply use only the method name or add the Query annotation I end up with the following stacktrace:

[EL Finest]: query: 2019-12-04 16:23:16.73--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Execute query ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
[EL Warning]: 2019-12-04 16:23:16.741--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Local Exception Stack: 
Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.QueryException
Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.NullPointerException].
Internal Exception: java.lang.NullPointerException
Query: ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
    at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1598)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:692)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:968)
...
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.NullPointerException
    at org.eclipse.persistence.internal.helper.NonSynchronizedVector.addAll(NonSynchronizedVector.java:315)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.getSelectionFields(ObjectLevelReadQuery.java:1808)
...

Debugging to the place where the exception is thrown shows me that in the RelationalDescriptor which appears to be used for the "getAllSelectionFields" the property allSelectionFields is null which causes the NullpointerException.

How can solve this? Is there something missing in the annotated entity class?

Many thanks in advance!

P.S.: I posted this question as well on stackoverflow, I hope it is OK reposting it to this user mailing list.


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ReadAllQuery fails in checkPrepare due to NullPointerException

Lukas Jungmann
On 12/13/19 3:32 PM, Chris wrote:
> I hit this and have a fix locally, but haven’t gotten around to checking
> bugzilla and submitting a patch. There are a few other issues with
> schema per tenant I’m looking into (sequencing with inheritance) as well.
>
> If you file it, I can upload the changes I have and see it fixes it for you.

or just go ahead and submit a PR at
https://github.com/eclipse-ee4j/eclipselink/pulls

thanks,
--lukas

>
>
>
> On Dec 13, 2019, at 5:32 AM, unimatrix-0 webmaster
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>> Dear all,
>>
>> I have a problem with schema based multitenancy:
>>
>> I am developing a multitenancy enabled application. The multitenancy
>> is schema based. Frameworks used so far are eclipselink 2.7.5, Spring
>> data jpa 2.2.0.RELEASE and PostgreSQL. Creating, finding and deleting
>> single entities works fine so far. A simple "findAll" works as well.
>> However I have a problem with custom repository methods.
>>
>> One entity is defined like this:
>>
>> |@Entity@Table(name
>> ="HISTORY")@Multitenant(MultitenantType.TABLE_PER_TENANT)@TenantTableDiscriminator(type
>> =TenantTableDiscriminatorType.SCHEMA,contextProperty
>> =PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)@IdClass(SimpleLongId.class)publicclassHistoryimplementsSerializable{@Id@TableGenerator(name
>> ="TABLE_GEN_HIST",table ="SEQUENCE_TABLE",pkColumnName
>> ="SEQ_NAME",valueColumnName ="SEQ_COUNT",pkColumnValue
>> ="HIST_SEQ")@GeneratedValue(strategy
>> =GenerationType.AUTO)Longid;@Column(nullable
>> =false)LongfkParentId;@Temporal(TemporalType.TIMESTAMP)@Column(nullable =true)privateDatelastrun;@Temporal(TemporalType.TIMESTAMP)@Column(nullable
>> =false)privateDatestartDateTime;@Temporal(TemporalType.TIMESTAMP)@Column(nullable
>> =true)privateDateendDateTime;@ColumnprivateStringstatus;@Temporal(TemporalType.TIMESTAMP)@Column(nullable
>> =false)privateDatemodified;@Temporal(TemporalType.TIMESTAMP)@Column(nullable
>> =false)privateDatecreated;@OneToMany(fetch =FetchType.EAGER,mappedBy
>> ="history",cascade =CascadeType.ALL)@JoinColumns({@JoinColumn(name
>> ="HISTORY_ID",referencedColumnName ="HISTORY_ID",nullable
>> =false)})@CascadeOnDeleteList<HistoryRecord>entries;publicLonggetId(){returnid;}publicvoidsetId(Longid){this.id
>> =id;}publicDategetLastrun(){returnlastrun;}publicvoidsetLastrun(Datelastrun){this.lastrun
>> =lastrun;}publicDategetStartDateTime(){returnstartDateTime;}publicvoidsetStartDateTime(DatestartDateTime){this.startDateTime
>> =startDateTime;}publicDategetEndDateTime(){returnendDateTime;}publicvoidsetEndDateTime(DateendDateTime){this.endDateTime
>> =endDateTime;}publicStringgetStatus(){returnstatus;}publicvoidsetStatus(Stringstatus){this.status
>> =status;}publicDategetModified(){returnmodified;}publicvoidsetModified(Datemodified){this.modified
>> =modified;}publicDategetCreated(){returncreated;}publicvoidsetCreated(Datecreated){this.created
>> =created;}publicList<HistoryRecord>getEntries(){returnentries;}publicvoidsetEntries(List<HistoryRecord>entries){this.entries
>> =entries;}publicLonggetFkParentId(){returnfkParentId;}publicvoidsetFkParentId(LongfkParentId){this.fkParentId
>> =fkParentId;}@PrePersistpublicvoidprePersist(){Datenow
>> =newDate();created =now;modified
>> =now;}@PreUpdatepublicvoidpreUpdate(){modified
>> =newDate();}publicStringtoString(){StringBuildersb
>> =newStringBuilder();sb.append("id: ").append(getId());sb.append(",
>> parentId: ").append(getFkParentId());sb.append(", created:
>> ").append(getCreated());sb.append(", modified:
>> ").append(getModified());sb.append(", startDateTime:
>> ").append(getStartDateTime());sb.append(", endDateTime:
>> ").append(getEndDateTime());sb.append(", Status:
>> ").append(getStatus());returnsb.toString();}} |As I want to be able to find all History entities by the field fkParentId I created an additional method in the repository:
>>
>> |@Query(value ="SELECT h FROM History h WHERE h.fkParentId =
>> :fkParentId",nativeQuery
>> =true)publicList<History>findAllByFkParentId(@Param("fkParentId")LongfkParentId);|
>>
>> Regardles if I simply use only the method name or add the Query annotation I end up with the following stacktrace:
>>
>> |[EL
>> Finest]:query:2019-12-0416:23:16.73--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Executequery
>> ReadAllQuery(referenceClass=Historysql="SELECT h FROM History h WHERE
>> h.fkParentId = :fkParentId")[EL
>> Warning]:2019-12-0416:23:16.741--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--LocalExceptionStack:Exception[EclipseLink-6168](EclipsePersistenceServices-2.7.5.v20191016-ea124dd158):org.eclipse.persistence.exceptions.QueryExceptionExceptionDescription:Queryfailed
>> to prepare,unexpected error
>> occurred:[java.lang.NullPointerException].InternalException:java.lang.NullPointerExceptionQuery:ReadAllQuery(referenceClass=Historysql="SELECT
>> h FROM History h WHERE h.fkParentId = :fkParentId")at
>> org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1598)at
>> org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:692)at
>> org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:968)...at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)Causedby:java.lang.NullPointerExceptionat
>> org.eclipse.persistence.internal.helper.NonSynchronizedVector.addAll(NonSynchronizedVector.java:315)at
>> org.eclipse.persistence.queries.ObjectLevelReadQuery.getSelectionFields(ObjectLevelReadQuery.java:1808)...
>> |
>>
>> Debugging to the place where the exception is thrown shows me that in
>> the RelationalDescriptor which appears to be used for the
>> "getAllSelectionFields" the property allSelectionFields is null which
>> causes the NullpointerException.
>>
>> How can solve this? Is there something missing in the annotated entity
>> class?
>>
>> Many thanks in advance!
>>
>> P.S.: I posted this question as well on stackoverflow, I hope it is OK
>> reposting it to this user mailing list.
>>
>> ||||
>> _______________________________________________
>> eclipselink-users mailing list
>> [hidden email] <mailto:[hidden email]>
>> To change your delivery options, retrieve your password, or
>> unsubscribe from this list, visit
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.eclipse.org_mailman_listinfo_eclipselink-2Dusers&d=DwICAg&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=aeYmvFwRsCWfafng1rj-AcoD-cr8mkJQBEoVD5OszU0&m=r72VDdYtbBgdxjtWqOvqsdllrloqRQbbcCVezFoad4Q&s=kkAyHlNFfzoXDRp97B5-QkwraKiLkEiwIpwrrnrjRP4&e= 
>
>
> _______________________________________________
> eclipselink-users mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/eclipselink-users
>
_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ReadAllQuery fails in checkPrepare due to NullPointerException

unimatrix-0 webmaster
In reply to this post by christopher delahunt
Ah! Many thanks Chris! And as usual I thought I made a mistake ;-) With "file it" you mean open an issue in github?

Am 13.12.19 um 15:32 schrieb Chris:
I hit this and have a fix locally, but haven’t gotten around to checking bugzilla and submitting a patch. There are a few other issues with schema per tenant I’m looking into (sequencing with inheritance) as well.

If you file it, I can upload the changes I have and see it fixes it for you.



On Dec 13, 2019, at 5:32 AM, unimatrix-0 webmaster <[hidden email]> wrote:

Dear all,

I have a problem with schema based multitenancy:

I am developing a multitenancy enabled application. The multitenancy is schema based. Frameworks used so far are eclipselink 2.7.5, Spring data jpa 2.2.0.RELEASE and PostgreSQL. Creating, finding and deleting single entities works fine so far. A simple "findAll" works as well. However I have a problem with custom repository methods.

One entity is defined like this:

@Entity
@Table(name = "HISTORY")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type = TenantTableDiscriminatorType.SCHEMA, contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
@IdClass(SimpleLongId.class)
public class History implements Serializable {
    @Id
    @TableGenerator(name = "TABLE_GEN_HIST",
            table = "SEQUENCE_TABLE",
            pkColumnName = "SEQ_NAME",
            valueColumnName = "SEQ_COUNT",
            pkColumnValue = "HIST_SEQ")
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;

    @Column(nullable = false)
    Long fkParentId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date lastrun;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date startDateTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date endDateTime;

    @Column
    private String status;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date modified;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date created;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "history", cascade = CascadeType.ALL)
    @JoinColumns({
            @JoinColumn(name = "HISTORY_ID", referencedColumnName = "HISTORY_ID", nullable = false)})
    @CascadeOnDelete
    List<HistoryRecord> entries;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getLastrun() {
        return lastrun;
    }

    public void setLastrun(Date lastrun) {
        this.lastrun = lastrun;
    }

    public Date getStartDateTime() {
        return startDateTime;
    }

    public void setStartDateTime(Date startDateTime) {
        this.startDateTime = startDateTime;
    }

    public Date getEndDateTime() {
        return endDateTime;
    }

    public void setEndDateTime(Date endDateTime) {
        this.endDateTime = endDateTime;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public List<HistoryRecord> getEntries() {
        return entries;
    }

    public void setEntries(List<HistoryRecord> entries) {
        this.entries = entries;
    }

    public Long getFkParentId() {
        return fkParentId;
    }

    public void setFkParentId(Long fkParentId) {
        this.fkParentId = fkParentId;
    }

    @PrePersist
    public void prePersist() {
        Date now = new Date();
        created = now;
        modified = now;
    }

    @PreUpdate
    public void preUpdate() {
        modified = new Date();
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("id: ").append(getId());
        sb.append(", parentId: ").append(getFkParentId());
        sb.append(", created: ").append(getCreated());
        sb.append(", modified: ").append(getModified());
        sb.append(", startDateTime: ").append(getStartDateTime());
        sb.append(", endDateTime: ").append(getEndDateTime());
        sb.append(", Status: ").append(getStatus());
        return sb.toString();
    }
}

As I want to be able to find all History entities by the field fkParentId I created an additional method in the repository:

    @Query(value = "SELECT h FROM History h WHERE h.fkParentId = :fkParentId", nativeQuery = true)
    public List<History> findAllByFkParentId(@Param("fkParentId") Long fkParentId);

Regardles if I simply use only the method name or add the Query annotation I end up with the following stacktrace:

[EL Finest]: query: 2019-12-04 16:23:16.73--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Execute query ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
[EL Warning]: 2019-12-04 16:23:16.741--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Local Exception Stack: 
Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.QueryException
Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.NullPointerException].
Internal Exception: java.lang.NullPointerException
Query: ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
    at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1598)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:692)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:968)
...
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.NullPointerException
    at org.eclipse.persistence.internal.helper.NonSynchronizedVector.addAll(NonSynchronizedVector.java:315)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.getSelectionFields(ObjectLevelReadQuery.java:1808)
...

Debugging to the place where the exception is thrown shows me that in the RelationalDescriptor which appears to be used for the "getAllSelectionFields" the property allSelectionFields is null which causes the NullpointerException.

How can solve this? Is there something missing in the annotated entity class?

Many thanks in advance!

P.S.: I posted this question as well on stackoverflow, I hope it is OK reposting it to this user mailing list.


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users



_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ReadAllQuery fails in checkPrepare due to NullPointerException

Lukas Jungmann
Yes, github is the best place for new issues.

Thanks,
—lukas 

16. 12. 2019 v 13:19, unimatrix-0 webmaster <[hidden email]>:


Ah! Many thanks Chris! And as usual I thought I made a mistake ;-) With "file it" you mean open an issue in github?

Am 13.12.19 um 15:32 schrieb Chris:
I hit this and have a fix locally, but haven’t gotten around to checking bugzilla and submitting a patch. There are a few other issues with schema per tenant I’m looking into (sequencing with inheritance) as well.

If you file it, I can upload the changes I have and see it fixes it for you.



On Dec 13, 2019, at 5:32 AM, unimatrix-0 webmaster <[hidden email]> wrote:

Dear all,

I have a problem with schema based multitenancy:

I am developing a multitenancy enabled application. The multitenancy is schema based. Frameworks used so far are eclipselink 2.7.5, Spring data jpa 2.2.0.RELEASE and PostgreSQL. Creating, finding and deleting single entities works fine so far. A simple "findAll" works as well. However I have a problem with custom repository methods.

One entity is defined like this:

@Entity
@Table(name = "HISTORY")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type = TenantTableDiscriminatorType.SCHEMA, contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
@IdClass(SimpleLongId.class)
public class History implements Serializable {
    @Id
    @TableGenerator(name = "TABLE_GEN_HIST",
            table = "SEQUENCE_TABLE",
            pkColumnName = "SEQ_NAME",
            valueColumnName = "SEQ_COUNT",
            pkColumnValue = "HIST_SEQ")
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;

    @Column(nullable = false)
    Long fkParentId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date lastrun;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date startDateTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date endDateTime;

    @Column
    private String status;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date modified;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date created;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "history", cascade = CascadeType.ALL)
    @JoinColumns({
            @JoinColumn(name = "HISTORY_ID", referencedColumnName = "HISTORY_ID", nullable = false)})
    @CascadeOnDelete
    List<HistoryRecord> entries;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getLastrun() {
        return lastrun;
    }

    public void setLastrun(Date lastrun) {
        this.lastrun = lastrun;
    }

    public Date getStartDateTime() {
        return startDateTime;
    }

    public void setStartDateTime(Date startDateTime) {
        this.startDateTime = startDateTime;
    }

    public Date getEndDateTime() {
        return endDateTime;
    }

    public void setEndDateTime(Date endDateTime) {
        this.endDateTime = endDateTime;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public List<HistoryRecord> getEntries() {
        return entries;
    }

    public void setEntries(List<HistoryRecord> entries) {
        this.entries = entries;
    }

    public Long getFkParentId() {
        return fkParentId;
    }

    public void setFkParentId(Long fkParentId) {
        this.fkParentId = fkParentId;
    }

    @PrePersist
    public void prePersist() {
        Date now = new Date();
        created = now;
        modified = now;
    }

    @PreUpdate
    public void preUpdate() {
        modified = new Date();
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("id: ").append(getId());
        sb.append(", parentId: ").append(getFkParentId());
        sb.append(", created: ").append(getCreated());
        sb.append(", modified: ").append(getModified());
        sb.append(", startDateTime: ").append(getStartDateTime());
        sb.append(", endDateTime: ").append(getEndDateTime());
        sb.append(", Status: ").append(getStatus());
        return sb.toString();
    }
}

As I want to be able to find all History entities by the field fkParentId I created an additional method in the repository:

    @Query(value = "SELECT h FROM History h WHERE h.fkParentId = :fkParentId", nativeQuery = true)
    public List<History> findAllByFkParentId(@Param("fkParentId") Long fkParentId);

Regardles if I simply use only the method name or add the Query annotation I end up with the following stacktrace:

[EL Finest]: query: 2019-12-04 16:23:16.73--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Execute query ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
[EL Warning]: 2019-12-04 16:23:16.741--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Local Exception Stack: 
Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.QueryException
Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.NullPointerException].
Internal Exception: java.lang.NullPointerException
Query: ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
    at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1598)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:692)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:968)
...
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.NullPointerException
    at org.eclipse.persistence.internal.helper.NonSynchronizedVector.addAll(NonSynchronizedVector.java:315)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.getSelectionFields(ObjectLevelReadQuery.java:1808)
...

Debugging to the place where the exception is thrown shows me that in the RelationalDescriptor which appears to be used for the "getAllSelectionFields" the property allSelectionFields is null which causes the NullpointerException.

How can solve this? Is there something missing in the annotated entity class?

Many thanks in advance!

P.S.: I posted this question as well on stackoverflow, I hope it is OK reposting it to this user mailing list.


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users

_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ReadAllQuery fails in checkPrepare due to NullPointerException

unimatrix-0 webmaster
In reply to this post by unimatrix-0 webmaster

I've filed the issue here: https://github.com/eclipse-ee4j/eclipselink/issues/639

Am 16.12.19 um 13:18 schrieb unimatrix-0 webmaster:
Ah! Many thanks Chris! And as usual I thought I made a mistake ;-) With "file it" you mean open an issue in github?

Am 13.12.19 um 15:32 schrieb Chris:
I hit this and have a fix locally, but haven’t gotten around to checking bugzilla and submitting a patch. There are a few other issues with schema per tenant I’m looking into (sequencing with inheritance) as well.

If you file it, I can upload the changes I have and see it fixes it for you.



On Dec 13, 2019, at 5:32 AM, unimatrix-0 webmaster <[hidden email]> wrote:

Dear all,

I have a problem with schema based multitenancy:

I am developing a multitenancy enabled application. The multitenancy is schema based. Frameworks used so far are eclipselink 2.7.5, Spring data jpa 2.2.0.RELEASE and PostgreSQL. Creating, finding and deleting single entities works fine so far. A simple "findAll" works as well. However I have a problem with custom repository methods.

One entity is defined like this:

@Entity
@Table(name = "HISTORY")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@TenantTableDiscriminator(type = TenantTableDiscriminatorType.SCHEMA, contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
@IdClass(SimpleLongId.class)
public class History implements Serializable {
    @Id
    @TableGenerator(name = "TABLE_GEN_HIST",
            table = "SEQUENCE_TABLE",
            pkColumnName = "SEQ_NAME",
            valueColumnName = "SEQ_COUNT",
            pkColumnValue = "HIST_SEQ")
    @GeneratedValue(strategy = GenerationType.AUTO)
    Long id;

    @Column(nullable = false)
    Long fkParentId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date lastrun;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date startDateTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = true)
    private Date endDateTime;

    @Column
    private String status;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date modified;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date created;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "history", cascade = CascadeType.ALL)
    @JoinColumns({
            @JoinColumn(name = "HISTORY_ID", referencedColumnName = "HISTORY_ID", nullable = false)})
    @CascadeOnDelete
    List<HistoryRecord> entries;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getLastrun() {
        return lastrun;
    }

    public void setLastrun(Date lastrun) {
        this.lastrun = lastrun;
    }

    public Date getStartDateTime() {
        return startDateTime;
    }

    public void setStartDateTime(Date startDateTime) {
        this.startDateTime = startDateTime;
    }

    public Date getEndDateTime() {
        return endDateTime;
    }

    public void setEndDateTime(Date endDateTime) {
        this.endDateTime = endDateTime;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public List<HistoryRecord> getEntries() {
        return entries;
    }

    public void setEntries(List<HistoryRecord> entries) {
        this.entries = entries;
    }

    public Long getFkParentId() {
        return fkParentId;
    }

    public void setFkParentId(Long fkParentId) {
        this.fkParentId = fkParentId;
    }

    @PrePersist
    public void prePersist() {
        Date now = new Date();
        created = now;
        modified = now;
    }

    @PreUpdate
    public void preUpdate() {
        modified = new Date();
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("id: ").append(getId());
        sb.append(", parentId: ").append(getFkParentId());
        sb.append(", created: ").append(getCreated());
        sb.append(", modified: ").append(getModified());
        sb.append(", startDateTime: ").append(getStartDateTime());
        sb.append(", endDateTime: ").append(getEndDateTime());
        sb.append(", Status: ").append(getStatus());
        return sb.toString();
    }
}

As I want to be able to find all History entities by the field fkParentId I created an additional method in the repository:

    @Query(value = "SELECT h FROM History h WHERE h.fkParentId = :fkParentId", nativeQuery = true)
    public List<History> findAllByFkParentId(@Param("fkParentId") Long fkParentId);

Regardles if I simply use only the method name or add the Query annotation I end up with the following stacktrace:

[EL Finest]: query: 2019-12-04 16:23:16.73--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Execute query ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
[EL Warning]: 2019-12-04 16:23:16.741--UnitOfWork(2097614581)--Thread(Thread[main,5,main])--Local Exception Stack: 
Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.QueryException
Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.NullPointerException].
Internal Exception: java.lang.NullPointerException
Query: ReadAllQuery(referenceClass=History sql="SELECT h FROM History h WHERE h.fkParentId = :fkParentId")
    at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1598)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:692)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:968)
...
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.NullPointerException
    at org.eclipse.persistence.internal.helper.NonSynchronizedVector.addAll(NonSynchronizedVector.java:315)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.getSelectionFields(ObjectLevelReadQuery.java:1808)
...

Debugging to the place where the exception is thrown shows me that in the RelationalDescriptor which appears to be used for the "getAllSelectionFields" the property allSelectionFields is null which causes the NullpointerException.

How can solve this? Is there something missing in the annotated entity class?

Many thanks in advance!

P.S.: I posted this question as well on stackoverflow, I hope it is OK reposting it to this user mailing list.


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users



_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users



_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users