[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] ReadAllQuery fails in checkPrepare due to NullPointerException
|
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
<webmaster@xxxxxxxxxxxxxx <mailto:webmaster@xxxxxxxxxxxxxx>> 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
eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
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
eclipselink-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/eclipselink-users