2022-12-13

Solved - ClassNotFoundException: org.springframework.boot.configurationprocessor.json.JSONObject

 
Exception:
java.lang.ClassNotFoundException: org.springframework.boot.configurationprocessor.json.JSONObject



Artifact below won't be included into maven install

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>



replaced

org.springframework.boot.configurationprocessor.json.JSONObject

by

org.json.JSONObject



 

2022-12-07

OAuthRequestAuthenticator : failed to turn code into token

 


I was having:


2022-12-07 09:21:25.077 ERROR 25057 --- [nio-8001-exec-4] o.k.adapters.OAuthRequestAuthenticator   : failed to turn code into token

java.net.ConnectException: Connection timed out (Connection timed out)
        at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_352]
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_352]
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_352]
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_352]
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_352]
        at java.net.Socket.connect(Socket.java:607) ~[na:1.8.0_352]
        at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:542) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.keycloak.adapters.SniSSLSocketFactory.connectSocket(SniSSLSocketFactory.java:109) ~[keycloak-adapter-core-4.5.0.Final.jar!/:4.5.0.Final]
        at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.3.jar!/:4.5.3]
        at org.keycloak.adapters.ServerRequest.invokeAccessCodeToToken(ServerRequest.java:111) ~[keycloak-adapter-core-4.5.0.Final.jar!/:4.5.0.Final]
        at org.keycloak.adapters.OAuthRequestAuthenticator.resolveCode(OAuthRequestAuthenticator.java:335) ~[keycloak-adapter-core-4.5.0.Final.jar!/:4.5.0.Final]
        at org.keycloak.adapters.OAuthRequestAuthenticator.authenticate(OAuthRequestAuthenticator.java:280) ~[keycloak-adapter-core-4.5.0.Final.jar!/:4.5.0.Final]
        at org.keycloak.adapters.RequestAuthenticator.authenticate(RequestAuthenticator.java:139) ~[keycloak-adapter-core-4.5.0.Final.jar!/:4.5.0.Final]
        at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.authenticateInternal(AbstractKeycloakAuthenticatorValve.java:203) ~[keycloak-tomcat-core-adapter-4.5.0.Final.jar!/:4.5.0.Final]
        at org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve.authenticate(KeycloakAuthenticatorValve.java:50) [keycloak-tomcat8-adapter-4.5.0.Final.jar!/:4.5.0.Final]
        at org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve.doAuthenticate(KeycloakAuthenticatorValve.java:57) [keycloak-tomcat8-adapter-4.5.0.Final.jar!/:4.5.0.Final]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:556) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:181) ~[keycloak-tomcat-core-adapter-4.5.0.Final.jar!/:4.5.0.Final]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:677) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_352]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_352]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
        at java.lang.Thread.run(Thread.java:750) [na:1.8.0_352]



Found out that server couldn't curl to keyclock which installed on the same machine by using public domain:

curl https://your.public.keycloak.com

curl: (7) Failed connect to your.public.keycloak.com:443; Connection timed out

 











2022-12-06

how to get mylyn task for eclipse

 



how to get mylyn task for eclipse



https://www.eclipse.org/mylyn/downloads/

Add URL into eclipse: http://download.eclipse.org/mylyn/releases/latest






Tried, outdate, not working.
https://people.cs.vt.edu/~gback/eclipse/configuration/org.eclipse.osgi/bundles/171/1/.cp/Mylyn/FAQ/Installation.html





2022-10-14

SVN with eclipse 2022-09




 



Attempt# 1 - failed:

Name: SVN

Location: http://download.Eclipse.org/technology/subversive/4.0/update-site/


reference URL: https://www.softwaretestinghelp.com/eclipse/configuring-svn-and-eclipse/



Attempt# 2


Last comment in: https://bugs.eclipse.org/bugs/show_bug.cgi?id=576745

https://www.eclipse.org/subversive/installation-instructions.php



Looks alright.


resolved by: remove "TLSv1, TLSv1.1"


Reference URL: https://stackoverflow.com/a/71050085

You can set it in JRE inside SoapUI (if you are using it): Remove "TLSv1, TLSv1.1" from "jdk.tls.disabledAlgorithms" property in file ${soapui_home}/jre/conf/securityjava.security.




Path at: .\Eclipse\eclipse-jee-2022-12-R-win32-x86_64\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.6.v20230204-1729\jre\conf\security\java.security








For later versions: 




 

2022-10-13

Resolved - Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible

 


Error:
Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @3d201878



By referring to:
https://stackoverflow.com/a/72616180



Added into <properties> section in pom.xml:

<maven-war-plugin.version>3.3.1</maven-war-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>





Added on 20230823_pm092210:
To resolve:
- Maven Configuration Problem - java.lang.ExceptionInInitializerError
- Unable to make field private final java.util.Comparator








2022-10-09

Reduce hibernate file

 


powercfg /hibernate /type reduced

reduced my hibernate file: C:\hiberfil.sys
from: 6.35 GB
to: 3.17 GB

But will disable your machine to go into hibernate...













2022-10-02

Steps to setup your new android phones and copy almost everything from old phone(android).




  1. Factory Reset / Turn on the new phone. 
  2. Select copy data from old phone.
  3. Answer to your new phone couldn't setup via cable.
  4. Continue copy data wirelessly.
  5. Follow the guide in new phone, to Open Google App in old phone, and continue as per instruction.





2022-09-29

2022-08-22

Corrupted GitLab 15.2 was back to online.

 




GitLab 15.2 was corrupted due to whatever reasons...


finally service back to running by:

sudo gitlab-ctl reconfigure
















2022-08-16

MySQL backup time consumed


version: 8.0.30


MySQL dump

zipped

100MB / 90 seconds

700MB+ / 10 mins




2022-08-03

Resolved: has been injected into other beans in its raw version as part of a circular reference

 
Resolved by referring to:
  1. https://www.baeldung.com/circular-dependencies-in-spring#2-use-lazy
  2. https://blog.51cto.com/u_13478207/3336383



has been injected into other beans in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.



structure to tell the story...

@Service
public class MainService{

    @Autowired
    private ServiceParent
}

@Service
public class ServiceParent{

    @Autowired
    private ServiceChild
    
}

@Service
public class ServiceChild{

    @Autowired
    private ServiceParent
    
}



then will hit the exception while maven run the application locally/at server.





@Service
public class ServiceChild{

    @Autowired
    @Lazy
    private ServiceParent
    
}
















2022-08-01

Keycloak 18.0.2

 

HTTP Error
302
401
500

clientId missing

solved by changing json config from installation as below

from:

  "auth-server-url": "http://localhost:9000/",
  "ssl-required": "none",
  "resource": "localsfaportal",

to:

  "url": "http://localhost:9000/",
  "ssl-required": "none",
  "clientId": "localsfaportal",



       [KEYCLOAK] Usage of legacy style promise methods such as `.error()` and `.success()` has been deprecated and support will be removed in future versions. Use standard style promise methods such as `.then() and `.catch()` instead.

resolved by changing init javascript

from:
keycloak.init().success().error()

to:
keycloak.init().then().catch()

has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.



Solved by adding * as print screen below:
















2022-07-27

Upgrade Spring Boot from 1.5.20.RELEASE to 2.7.2


as of: 20220727_pm070452, Still editing...

Stacks

From Spring Boot + Keycloak
To: Spring Boot + Keycloak + Spring Security 


Version

from: 1.5.20.RELEASE
to: 2.7.2


Changes

  1. pom.xml
  2. CSRF - default implementation of Spring Security
    1. JSP
  3. Controllers
  4. Services
    1. Repo
      1. Batch Save
      2. Batch Delete
      3. Delete
      4. FindOne
      5. Pageable
  5. application.properties









pom.xml

Added


<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>


<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
<version>18.0.2</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-security-adapter</artifactId>
<version>18.0.2</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>







<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>${version.keycloak-adapter-bom}</version>
<type>pom</type>
</dependency>















Modified

from:
  <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.20.RELEASE</version>
</parent>

to:
  <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
</parent>

from:

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR5</spring-cloud.version>
</properties>

to:

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>com.tiongnam.sfa.cdr.MainClass</start-class>
<spring-cloud.version>2021.0.3</spring-cloud.version>
<version.keycloak-adapter-bom>18.0.2</version.keycloak-adapter-bom>
</properties>





from:

<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-adapter</artifactId>
<version>4.5.0.Final</version>
</dependency>


to:

<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-adapter</artifactId>
<version>18.0.2</version>
</dependency>


















CSRF - default implementation of Spring Security




Added header into ajax post request

, headers: {"${_csrf.headerName}": '${_csrf.token}'}

Added spring security tag within POST form:

<sec:csrfInput />


or


turn off csrf checking


protected void configure(HttpSecurity http) throws Exception {

org.springframework.security.config.annotation.web.builders.HttpSecurity http.csrf().disable();

...
...

































Controllers:


Changed

From:
org.keycloak.KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal

To:
java.security.Principal principal











Services

Batch Save

Changed

From:
repo.save(batchList)

To:
repo.saveAll(batchList);



findOne

From:
repo.findOne(new Long("1"));


To:
repo.getReferenceById(new Long("1"));



Delete


From:
delete(entity.getId());

To:
deleteById(entity.getId());







Pageable


From:
Pageable page_req = new PageRequest(index,reqData.getLength(), orderBy(reqData), reqData.getOrder().getData());

To:
Pageable page_req = PageRequest.of(index, reqData.getLength(), orderBy(reqData), reqData.getOrder().getData());










application.properties


Added

server.tomcat.max-http-form-post-size
server.tomcat.max-swallow-size

Changed


server.contextPath

to

server.servlet.context-path






spring.http.multipart.max-file-size

to

spring.servlet.multipart.max-file-size



spring.http.multipart.max-request-size

to

spring.servlet.multipart.max-request-size









keycloak.securityConstraints[0].authRoles[0]=read-only-common
keycloak.securityConstraints[0].securityCollections[0].patterns[0]=/welcome
keycloak.securityConstraints[0].securityCollections[0].patterns[1]=/logout
keycloak.securityConstraints[0].securityCollections[0].patterns[2]=/dashboard
keycloak.securityConstraints[0].securityCollections[0].patterns[3]=/web/getDashboard



to



@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests()
.antMatchers("/vendor/**", "/css/**", "/js/**", "/img/**").permitAll()
.antMatchers("/upload").authenticated()
.antMatchers("/formd/**", "/module1/**", "/maintenance/**").authenticated()
.anyRequest().authenticated()
;
}













2022-07-21

ajax, upload file, json string, Spring Controller, DTO

 



Googled: json to dto spring boot controller




Resolved by follow the example on: 

Spring Boot controller - Upload Multipart and JSON to DTO




thread solution at: https://stackoverflow.com/a/49993072


Ajax Javascript
formData.append( 'dtoName', new Blob([JSON.stringify(dtoJavascriptObject)], {
type: "application/json"
}));

Spring Controller parameter

@RequestPart ManualGenerateCsv dtoName






couldn't parse json attribute to java object attribute.

 







private boolean isRequiredFtpToSSS;

public void setRequiredFtpToSSS(boolean isRequiredFtpToSSS) {
this.isRequiredFtpToSSS = isRequiredFtpToSSS;
}

Since your attribute name: isRequiredFtpToSSS
Due to jackson is expecting: setIsRequiredFtpToSSS
But there has no "is for the auto generated setter: setRequiredFtpToSSS





So u have to add this.

@JsonProperty("isRequiredFtpToSSS")
private boolean isRequiredFtpToSSS;


















Jackson JSON parsing from string to date.

 









@JsonFormat(pattern = "yyyy-MMM-dd")
private Date dateFrom;





not sure if were causing by:
MethodArgumentConversionNotSupportedException when I try to map json string onto java domain class in Spring controller's method






jquery 3.3.1 change checkbox checked

 







Found: 
Make checkbox value checked with jQuery or JavaScript
but seems not the same case.



the one i'm using.

$("#chkHasDateTo").prop('checked', dto.hasDateTo);



But i remember there are more elegant way to do the same thing....

Jquery Datepicker: click on a checkbox, then open/pop datepicker of a textbox.

 


click on a checkbox, then open/pop datepicker of a textbox.



if($("#chkHasDateTo").is(":checked")){
$( "#dateTo" ).trigger( "select" );
$( "#dateTo" ).trigger( "focus" );
}

















2022-07-13

全 #Lesley [Legend V] #MVP 7.7/6 4 6 | $13383 202206142025

 




全 #Lesley [Legend V] #MVP 7.7/6 4 6 | $13383 202206142025 https://youtu.be/tnp0nELuY8Q via @YouTube #MLBB 



Java does new instance consume many memory

 







Found: https://stackoverflow.com/a/258150

Measurement methods

You can use Instrumentation.getObjectSize() to obtain an estimate of the storage consumed by an object.








eclipse maven "JUnit" "javaagent"

refer to: https://www.blogger.com/blog/post/edit/10648886/7778852398276118981





















eclipse maven "JUnit" "javaagent"

 


eclipse maven "JUnit" "javaagent"








Found this:

https://stackoverflow.com/a/35775792

You can use ea-agent-loader

With it loading an agent in runtime will look like:

public class HelloAgentWorld
{
    public static class HelloAgent
    {
        public static void agentmain(String agentArgs, Instrumentation inst)
        {
            System.out.println(agentArgs);
            System.out.println("Hi from the agent!");
            System.out.println("I've got instrumentation!: " + inst);
        }
    }

    public static void main(String[] args)
    {
        AgentLoader.loadAgentClass(HelloAgent.class.getName(), "Hello!");
    }
}

全 #Rafaela [Epic I] #MVP 9.6/4 3 21 | $8313 202205281332 https://youtu.be/jUNpF3a8HPI via @YouTube #MLBB

 


全 #Rafaela [Epic I] #MVP 9.6/4 3 21 | $8313 202205281332 https://youtu.be/jUNpF3a8HPI via @YouTube #MLBB 




2022-07-12

eclipse added hotkey for svn actions are not working.


It may be due to this breaking change in Eclipse 3.6:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.platform.doc.isv/porting/3.6/incompatibilities.html?view=co#objectContribution

EDIT:

Looks like it definitely is. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=309074. Here's the fix:

In the "Customize Perspective" dialog, go to the "Command Groups Availability" tab and check "Team" and "SVN".

In Eclipse Mars.2 (4.5.2) this is under Window->Perspective->Customize Perspective... dialog, "Action Set Availability" tab. (Try to restart Eclipse if it doesn't work after you change it). Customize Perspective dialog screenshot







Right click on current perspective:




Click on Customize...

Click on "Action Set Availability"



From Available action sets column:



Tick / Check the SVN checkbox, then Apply and Close.

Tested without restart eclipse, the hot key is working now.

























2022-07-06

Resolved - @PreUpdate not working in JUnit test.

 



javax.persistence.PreUpdate





object need to be "dirty" to trigger...


obj.setColumn01("text");
repo.save(obj);


then make obj "dirty" before save to trigger @PreUpdate


obj.setColumn01("new text);
repo.save(obj);




Solution

As you said, the callback method is called the second time, if the entity is detached or fetched again from DB.

I cannot explain it exactly, but can think of the scenario described here, when no dirty fields are identified before the second save() call and thus the @PreUpdate callback not called. Or it may be simply a bug within your version of EclipseLink.

2022-07-01

Setup local Keycloak for development

 




https://stackoverflow.com/a/72600716






Keycloak 18.0.2 doesn't required "/auth" as endpoint


new config:

keycloak.auth-server-url=http://localhost:8080

would be enough




We are sorry... page not found... error


Mandatory Config in Keycloak



while hitting we are sorry page not found error

was using http://localhost:8080/auth for keycloak.auth-server



while testing with https://www.keycloak.org/app/

hit error if didn't fill: https://www.keycloak.org/app/
to:

Root URL: https://www.keycloak.org/app/




If cofnig below never in place, will trigger error: Invalid parameter: redirect_uri


Valid Redirect URIs: *








Respective Keycloak role in Spring Boot authRole config

 





keycloak.securityConstraints[0].authRoles[0]=xyz





Respective config in Keycloak (18.0.2)

In user Role mappings:





Different of SVNs

 SVN




Getting(install) SVN feature from
Eclipse Marketplace... VS  Install New Software






Eclipse Marketplace...





Install New Software

http://subclipse.tigris.org/update_1.6.x







subclipse.tigris.org no longer available...

 

http://subclipse.tigris.org/update_1.10.x
http://subclipse.tigris.org/update_1.6.x

above are not reachable...








Found a post telling to get from Eclipse Marketplace

Help > Eclipse Marketplace...





But during installation, but still retrieve resource from:












2022-06-10

"Spring" JPA "native query" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

 


"Spring" JPA "native query" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1



Exception Snippet:

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(ArrayList.java:659)
at java.util.ArrayList.get(ArrayList.java:435)
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.toMap(ResultProcessor.java:278)
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.getProjectionTarget(ResultProcessor.java:266)
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.convert(ResultProcessor.java:253)
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter$1.convert(ResultProcessor.java:201)
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convert(ResultProcessor.java:212)
...

Throw error with:

List<Map<String, Object>> getNativeQueryList();

or

List<Tuple> getNativeQueryList();

Work around with:

List<Object[]> getNativeQueryList();






JUnit test - Caused by: javax.persistence.RollbackException: Transaction marked as rollbackOnly

 

Exception snippet:

12:02:34.849|WARN |Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@1a84f40f] to process 'after' execution for test: method [public void test.com.tiongnam.repositories.TestInvoicePackageRepo.testListPossiblePackageWithInvoiceIdAndSummary()], instance [test.com.tiongnam.repositories.TestInvoicePackageRepo@ca2cd5e], exception [java.lang.IndexOutOfBoundsException: Index: 1, Size: 1]|main|org.springframework.test.context.TestContextManager
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.test.context.transaction.TransactionContext.endTransaction(TransactionContext.java:128)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:227)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:319)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:94)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
...
Caused by: javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:58)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
... 26 common frames omitted





@Rollback(false)
MyJUnitTestClass


Calling a @Transactional Repo



change
@Rollback(true)






2022-05-31

Alternative - Error Code: 1093. You can't specify target table 'YOUR_TABLE' for update in FROM clause

 




Error Code: 1093. You can't specify target table 'YOUR_TABLE' for update in FROM clause



UPDATE YOUR_TABLE SET columnA = 'def' WHERE id IN (SELECT id AS MMID FROM YOUR_TABLE WHERE columnA = 'abc');



UPDATE YOUR_TABLE SET columnA = 'def' WHERE id IN ( SELECT MMID FROM ( SELECT id AS MMID FROM YOUR_TABLE WHERE columnA = 'abc' ) AS YOUR_ALIAS );



2022-04-20

JasperReport, always get blank PDF?

 
line below with new JREmptyDataSource() will get pdf as per expected.

jasperPrint = JasperFillManager.fillReport(report, jrParam, new JREmptyDataSource());



vs

where as using static _DATA_SOURCE_EMPTY, will always get blank pdf.

private static JREmptyDataSource _DATA_SOURCE_EMPTY = new JREmptyDataSource();

...
jasperPrint = JasperFillManager.fillReport(report, jrParam, _DATA_SOURCE_EMPTY);
...










2022-04-14

Multiple JasperPrint into a pdf with output as file and byte[]

 Multiple JasperPrint into a pdf with output as file and byte[]

JasperExportManager.exportReportToPdf vs JRPdfExporter.exportReport()








Found: https://community.jaspersoft.com/questions/526021/how-merge-multiple-pdf-jasper-reports-one







Multiple JasperPrint into a file
setCreatingBatchModeBookmarks

public void pdf() throws JRException { long start = System.currentTimeMillis(); List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>(); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report1.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report2.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report3.jrprint")); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("build/reports/BatchExportReport.pdf")); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setCreatingBatchModeBookmarks(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); }



JRPdfExporter to byte array

Found: https://www.tabnine.com/code/java/methods/net.sf.jasperreports.engine.export.JRPdfExporter/setParameter

public byte[] exportToPdf(JasperPrint jasperPrint) throws JRException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(jasperReportsContext); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos)); exporter.exportReport(); return baos.toByteArray(); }




more Java JRPdfExporter.exportReport方法代碼示例
Found: https://vimsky.com/zh-tw/examples/detail/java-method-net.sf.jasperreports.engine.export.JRPdfExporter.exportReport.html


示例1: export
示例2: savePDFReportToOutputStream
示例3: concatPDFReport
示例4: concatPDFReportEncrypted


Billson: file
示例5: pdf























Google Referrals