I'm trying to call an Oracle procedure using Persistence API:
#TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeProcess(User user, BigDecimal processId) {
EntityManager em = emb.createEntityManager(user);
em.createNativeQuery("{ call DOF.DF#DEL_PROCESS(?) }")
.setParameter(1, processId)
.executeUpdate();
em.close();
}
And I got the following exception:
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Invalid column index
Error Code: 17003
Call: { call DOF."DF?)" }
bind => [1 parameter bound]
If i copy DF#DEL_PROCESS to DF_DEL_PROCESS all works fine. How can I escape # in the procedure name??
'#' is the default parameter marker used internal in EclipseLink.
You can change this using the query hint, "eclipselink.jdbc.parameter-delimiter"
Also, if you inline the parameter instead of using setParameter() it should also work.
Related
Jpa repositoy methods called from inside of a #Scheduled method is throwing PSQLException and saying the relation does not exist, where the same repository method is being executed fine without any problems from other parts of the code.
This is my #Configuration class for Scheduler,
#Configuration
#EnableScheduling
public class SchedulingConfig {
#Bean
public TaskScheduler taskScheduler() {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
executor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("Scheduled-%d").build());
ConcurrentTaskScheduler taskScheduler = new ConcurrentTaskScheduler(executor);
taskScheduler.setTaskDecorator(new MasterTaskDecorator());
return taskScheduler;
}
}
And this is the #Scheduled annotated method,
#Scheduled(fixedRate = 60000, initialDelay = 60000)
public void scheduledRevalidationOfOpenJourney() {
List<JourneyEntity> openJourneys = journeyRepository.findAllByState(JourneyState.OPEN);
openJourneys.forEach(openJourney -> openJourney.getDatasets().forEach(validationService::removeRelatedViolation));
}
From there on, this is the exception being thrown,
2022-12-02 15:22:58.894 ERROR 32704 --- [ scheduling-1] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: relation "journey" does not exist
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
2022-12-02 15:23:58.896 ERROR 32704 --- [ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.postgresql.util.PSQLException: ERROR: relation "journey" does not exist
As I mentioned before, the table 'journey' does already exist and its repository methods are already being executed without any problems elsewhere in the code. Can anybody please point out what is causing this scenario and what could be the solution to it?
I have an entity like the following:
public class OrganizationUser {
// stuff
#Transient
public List<ExternalUserLink> externalUserLinks;
}
My code is persisting a completely unrelated object, but I'm getting an exception:
org.springframework.orm.jpa.JpaSystemException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.4.v20190115-ad5b7c6b2a): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: relation "organizationuser_externaluserlink" does not exist
Position: 217
Error Code: 0
Call: SELECT t1.id, t1.VALUE1, t1.VALUE2 FROM ORGANIZATIONUSER_EXTERNALUSERLINK t0, EXTERNALUSERLINK t1 WHERE (((t0.organizationUser_id = ?) AND (t1.id = t0.externalUserLinks_id))
bind => [e1bf9c52-71d0-11ec-9152-0242ac120006]
Query: ReadAllQuery(name="externalUserLinks" referenceClass=ExternalUserLink sql="SELECT t1.id, t1.VALUE1, t1.VALUE2 FROM ORGANIZATIONUSER_EXTERNALUSERLINK t0, EXTERNALUSERLINK t1 WHERE (((t0.organizationUser_id = ?) AND (t1.id = t0.externalUserLinks_id))"); nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.4.v20190115-ad5b7c6b2a): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: relation "organizationuser_externaluserlink" does not exist
Position: 217
Error Code: 0
ExternalUserLink is also an entity and does not have any annotated references to OrganizationalUser (it does contain a UUID called orgUserId that refers to the OrganizationalUser, but this is not mentioned in annotations).
In fact, there is no such table or entity, and the IDs between OrganizationalUser and ExternalUserLinks are not related in any way but EclipseLink seems to have inferred some kind of relationship despite the #Transient annotation. (Let alone as to why this query would even be invoked for an unrelated flush).
What is going on and how can I fix this problem?
After a bit more digging it turns out my "I'm too smart for you IDE" decided to pull in org.springframework.data.annotation.Transient instead of the proper javax.persistence.Transient. Since this is the wrong annotation with the same name, JPA took it upon itself to map this list to a new table.
spring boot 2.0
spring data jpa 2
#Modifying
#Query(name = "delete from User a where age=?1 and username=?1")
void deleteByAge(int i);
#Query is invalid. Did not execute the JPQL I wrote
question 2:
#Modifying
#Query(name = "delete from User a where age=?1 and username=?1")
void dByAge(int i);
spring boot startup exception:
Invocation of init method failed; nested exception is
java.lang.IllegalArgumentException: Failed to create query for method
public abstract void
com.unuobi.testboot.repository.UserRepository.dByAge(int)! No property
dByAge found for type User!
✔ #Query(value="select ....")
✖ #Query(name="select ....")
must be value ,
Use this as JPQL Query required age and username so both has to pass in your method , whatever type username is and they should be always in sequence they used in #Query:
#Modifying
#Query("delete from User a where age=?1 and username=?1")
void deleteByAge(int age, String username);
Or named query can be:
void deleteByAgeAndUsername(int age, String username);
make sure you have age and username in User entity.
I'am new in JAVA and JPA.
I use command
select * from asm.attendant where staff_no='0004' and node_code='KT1' and date(attendant_date) = '2013-05-13';
in MySQL it's work
but
when i use in JPA
public List<Attendant> listAttendantByStaffNoAndNodeCodeAndDateWs(String staffNo,String nodeCode,String attendantDateData) throws ParseException {
Date attendantDate = new SimpleDateFormat("yyyy-MM-dd").parse(attendantDateData);
Query result = em.createQuery("SELECT a FROM Attendant a WHERE a.staffNo = :staffNo AND a.nodeCode = :nodeCode AND DATE(a.attendantDate) = :attendantDate", Attendant.class);
result.setParameter("staffNo", staffNo);
result.setParameter("nodeCode", nodeCode);
result.setParameter("attendantDate", attendantDate);
return result.getResultList();
}
it's not work.
error
Caused by: Exception [EclipseLink-8025] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing the query [SELECT a FROM Attendant a WHERE a.staffNo = :staffNo AND a.nodeCode = :nodeCode AND DATE(a.attendantDate) = :attendantDate], line 1, column 88: unexpected token [(].
Internal Exception: NoViableAltException(83#[()* loopback of 383:9: (d= DOT right= attribute )*])
DATE() is not valid JPQL. In JPA createQuery() takes JPQL not SQL. If you want SQL use createNativeQuery().
Or, in JPQL just mark the date as a parameter :date any set the parameter to your instance of java.sql.Date.
When I am debugging Spring application in Eclipse, I am getting long exception chains. For example, I have
Error creating bean with name '...' defined in file [...Tester.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property '...' threw exception; nested exception is java.lang.IllegalArgumentException: ...
And so on. Multiple stacks with exceptions inside Spring, which is uninteresting. It should be my exceptions somewhere below, but Spring does not show them.
And I can't click into exception and navigate to problem place as usual.
How to say Spring to output all exceptions?
UPDATE
Below is the full output. One can see that the place where IllegalArgumentException occurred was probably truncated.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybean' defined in file [D:\mypath\myconfig.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'myproperty' threw exception; nested exception is java.lang.IllegalArgumentException: my exception message
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:84)
at springtests.SpringRunner.main(SpringRunner.java:8)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'target.partner' threw exception; nested exception is java.lang.IllegalArgumentException: Illegal frame length 1 in explicit constructor
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
... 13 more
Because there are potentially multiple exceptions, you need to catch the PropertyBatchUpdateException and call getPropertyAccessExceptions() to examine the stack trace of the particular exception.
Edit
Actually I'm not quite sure what's going on here
Here is PropertyBatchUpdateException's printStackTrace method:
public void printStackTrace(PrintWriter pw) {
synchronized (pw) {
pw.println(getClass().getName() + "; nested PropertyAccessException details (" +
getExceptionCount() + ") are:");
for (int i = 0; i < this.propertyAccessExceptions.length; i++) {
pw.println("PropertyAccessException " + (i + 1) + ":");
this.propertyAccessExceptions[i].printStackTrace(pw);
}
}
}
It should be including the nested stack traces. Are you using the latest version of Spring?
Edit:
The best I can suggest is to run in debug mode, then put a breakpoint at AbstractAutowireCapableBeanFactory.java:1361 and see what's going on.