Functional operators causes JPA to crash? (Bug?) - jpa

I'm having a very strange problem with JPA and Java 8 functional programming.
I have a Student and Presentation class and their relationship is bidirectional. Everything worked fine in Java 7, but I just switched to Java 8.
This works (visible is private, has no setters):
public static void setAllVisible(boolean visible) {
for (Presentation presentation : new PresentationRepository().findAll()) {
presentation.visible = visible;
}
}
This crashes:
public static void setAllVisible(boolean visible) {
new PresentationRepository().findAll().forEach(x -> x.visible = visible);
//same for new PresentationRepository().findAll().stream().forEach(x -> x.visible = visible);
}
Which gives this exception multiple times:
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader#4554617c
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [BachelorproefPU] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class models.users.Student] uses a non-entity [class models.planning.Presentation] as target entity in the relationship attribute [field presentation].
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at persistence.JPAEntityManager.getEntityManagerFactory(JPAEntityManager.java:45)
at models.repositories.Repository.<init>(Repository.java:23)
at models.repositories.UserRepository.<init>(UserRepository.java:15)
at main.DbInitializer.<init>(DbInitializer.java:27)
at main.DbInitializer.main(DbInitializer.java:23)
I'm pretty sure the persistence.xml is configured correctly (because it works without Java 8) and all classes are included and have #Entity. It's also not the Student class, because if I comment that out, the error just gives another class.
What's causing this? Maybe it's also worth mentioning that I get a compile crash once a while and that they ask me to send the project to Oracle.

Think you'll find that current EclipseLink doesn't support Java 1.8 syntaxis; look at
https://github.com/averri/jpa-lambda-integration-test
I use DataNucleus v4.0 for my projects and works for Java 1.8

Related

Weaving with EclipseLink fails with NPE

Performing weaving (static or dynamic) results in the following error:
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.1.v20171221-bd47e8f): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [MyUnit] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:231)
... 20 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.sessions.Project.hasSQLResultSetMapping(Project.java:1040)
at org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata.hasResultSetMapping(NamedNativeQueryMetadata.java:141)
at org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata.process(NamedNativeQueryMetadata.java:172)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processQueries(MetadataProject.java:1713)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.addNamedQueries(MetadataProcessor.java:153)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2024)
I didn't get this error with EclipseLink 2.6.5 and if I turn Weaving off everything works fine.
Is there a way to work around it? What triggers the error?
The NPE is a bug, as it isn't performing a null check and throwing a more specific error: This error could only occur if you've specified a named native (SQL) query on your entities that references a SqlResultSetMapping, but you haven't defined any result sets mappings. See https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Native#SQL_Result_Set_Mapping for documentation and an example.

How to load database configuration from preferences in eclipse e4 rcp?

I am trying to load and use my database configuration from preferences as suggested here using properties = {...} approach, but it is not working.
I get the following exception:
WARNING: EMFProxy invocation on method isOpen failed: Exception: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20130815-a4708b6): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: URL was not specified
The problem persists even if I hard code the values in properties using value=.... It somehow does not read the properties.
I fixed it! I wanted the PersistenceUnitProperties.JDBC_DRIVER to be static so I left it in the persistence.xml and did not add it programmatically. The problem was fixed when I removed it from persistence.xml and set it also programmatically.

com.google.cloud.sql.jdbc.internal.ClientSideClob causes 500 error, apps are unusable

Woke up this morning with this error coming from google.cloud.sql.jdbc
We have been using the OData library Oligno v2 for months and for no apparent reason this morning it stopped working. Our apps and services are down.
{"error":{"code":null,"message":{"lang":"en","value":"\"OData - JPA
Runtime: JPA query syntax is not correct\""},"innererror":"class
org.eclipse.persistence.exceptions.ConversionException : \nException
Description: The object [], of class [class
com.google.cloud.sql.jdbc.internal.ClientSideClob], could not be
converted to [class java.lang.String].\nInternal Exception: Exception
[EclipseLink-4002] (Eclipse Persistence Services -
2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.DatabaseException\nInternal
Exception: java.sql.SQLException: Invalid parameter for pos value
1\nError Code: 0"}}
Setup:
java google app engine
angular app on the front
Java EE backend with the oligno v2 library https://olingo.apache.org/doc/odata2/download.html
simply calling something like http://app.server/odata.svc/Tasks returns this error, it's like the oData library is not compatible anymore with GAE and Cloud SQL
There is an issue with the connection, here is the discussion: https://groups.google.com/forum/#!topic/google-appengine/Oc-wJvvCXgE
Please fill out this form if issue still persists:
https://code.google.com/p/googleappengine/issues/detail?id=12066&thanks=12066&ts=1434572430

JPA: Modelling a Map<Entity, Entity>

I am running into an exception when generating the database tables with EclipseLink for the following model:
#Entity
#Table(name="RXRACTSPOT")
public class ActivitySpot implements Serializable,IsSerializable {
.....
#OneToMany
private Map<CustomAttributeDefinition, CustomAttributeRestriction> customAttributes;
--
#Entity
#Table(name="RXRCUSTATTRREST")
public class CustomAttributeRestriction implements Serializable
--
#Entity
#Table(name="RXRCUSTATTRDEF")
public class CustomAttributeDefinition implements Serializable
I encounter the following exception:
Exception in thread "main" javax.persistence.PersistenceException: Exception >[EclipseLink-0] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
Exception [EclipseLink-93] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [RXRCUSTATTRREST] is not present in this descriptor.
Descriptor: RelationalDescriptor(com.rubiconred.activitystream.core.model.ActivitySpot --> [DatabaseTable(RXRACTSPOT)])
Runtime Exceptions:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:417)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
at com.rubiconred.activitystream.database.ActivityStreamDatabaseUtils.dropAndCreateTables(ActivityStreamDatabaseUtils.java:64)
at com.rubiconred.soauiext.server.db.CreateOneSpotDatabases.main(CreateOneSpotDatabases.java:16)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.IntegrityException
If I remove the Map in RXRACTSPOT then the tables RXRCUSTATTREST and RXRCUSTATTRDEF are successfully created. With the Map neither table is created and the exception is thrown. I suspect I am missing some annotation on the Map but I have been unable to find an example for a Map with both key and value as Entities.
Seems like a bug. Try the latest release, if it still occurs please log a bug.
You could also create another Entity class to represent the three way join table instead of using a Map.

Why does EclipseLink think my database schema doesn't exist?

I'm working on a web project using EJB 3.0, and whenever EclipseLink tries to interact with the database, it says that the schema I'm using doesn't exist (which it does).
I get a massive, unhelpful stack trace from GlassFish 2.1, which begins with:
EclipseLink, version: Eclipse Persistence Services - 1.1.0.r3639-SNAPSHOT
file:/C:/Documents%20and%20Settings/nick/.personalDomain/personalDomain/applications/j2ee-apps/ScienceEar/lib/ScienceJpa-1.0-SNAPSHOT.jar-SciencePU login successful
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.1.0.r3639-SNAPSHOT): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Schema 'BEAMLINE' does not exist
Error Code: -1
Call: SELECT exp_id, fac_family, public_viewable, group_name, created_ts, status, exp_num, date_received, exp_type, title, updated_ts, text_only_title, experiment_url, proposed_eec, start_of_prep FROM beamline.eec_exp_toc
Query: ReadAllQuery(name="Experiment.findAll" referenceClass=Experiment sql="SELECT exp_id, fac_family, public_viewable, group_name, created_ts, status, exp_num, date_received, exp_type, title, updated_ts, text_only_title, experiment_url, proposed_eec, start_of_prep FROM beamline.eec_exp_toc")
I could post more of the stack trace, but it's really boring. Any ideas for why EclipseLink can't see the schema?
More info: "beamline" is the only schema I use. The SQL in the stack trace is the stuff that was generated by a NamedQuery, the first interaction with this database (and the first JPA interaction at all) in my program.
Got it - I'm connecting directly to the database, when I should be using GlassFish's connection pool.