JPA 2.0 (logging and tracing through) with Glassfish 3.0.1 and NetBeans 6.9.1: - debugging

I am using JPA 2.0 (EclipseLink provider) with Glassfish v3.0.1 and NetBeans 6.9.1 and am NOT able to see the queries and other logging information from JPA 2.0. Essentially I want to be able to see all the SQL statements which are being generated by JPA and other related debugging information...
Has anyone successfully been able to configure the logging to provide such feedback? I've tried several things to no avail...
Any help would be greatly appreciated.
Thanks much.

What eventually had done the trick for me was using:
<property name="eclipselink.logging.logger"
value="org.eclipse.persistence.logging.DefaultSessionLog"/> in conjunction with your recommended tag of:
<property name="eclipselink.logging.level" value="FINE" /> This allowed me to see the relevant JPA logs which in NetBeans output window. This also worked in Eclipse. The output was sent do the console window an intermingled with the server's output which was exactly what I wanted.

You must configure logging level in persistence.xml file.
Example:
<persistence-unit name="MY_POOL_NAME" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>MY_JTA_SOURCE</jta-data-source>
<properties>
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.target-server" value="SunAS9"/>
</properties>
</persistence-unit>
Log Levels:
OFF
SEVERE
WARNING
INFO
CONFIG - Use this for Production
FINE
FINER
FINEST
More info: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging
All the queries would be printed in the domain server.log file.

Related

Access spring profile in log4j2 for spring boot application

How can i access the ${spring.profiles.active} value in log4j2 so that i can append the logfile name based on the profile?
log4j2.xml
<Properties>
<Property name="log-path">c:/logs</Property>
<Property name="targetEnv">${spring.profiles.active}</Property>
</Properties>
I tried with the following configuration and it worked
<Property name="targetEnv">${sys:spring.profiles.active}</Property>
This might help someone who is facing the same problem

How can I enhance classes for openJPA with gradle

I am stuck setting up a simple test program with
- eclipse
- gradle (Eclipse Buildship plugin)
- openjpa
When I try to run my application I get this error, when I call the entityManager.persist(...) method:
Exception in thread "main" org.apache.openjpa.persistence.ArgumentException: Attempt to cast instance "test.jpa.Person#27c6e487" to PersistenceCapable failed. Ensure that it has been enhanced.
FailedObject: test.jpa.Person#27c6e487
The program is simple, it just has one entity (Person.java).
My persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="ptest"
transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/ptest" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionUserName" value="..." />
<property name="openjpa.ConnectionPassword" value="..." />
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported" />
<property name="openjpa.DynamicEnhancementAgent" value="false" />
<property name="openjpa.Log" value="SQL=ERROR" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="openjpa.ConnectionFactoryProperties"
value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000" />
</properties>
</persistence-unit>
</persistence>
I have used RuntimeUnenhancedClasses=unsupported and DynamicEnhancementAgent=false, for it was recommended by apache. But I have tried with "supported" and "true" and I still get the same error (for openjpa version 2.1.0 - for higher versions I get a LinageError with "supported/true").
I have tried different versions of jpa, currently using 2.4.2.
I have goodled for gradle scripts to enhance my class, I tried
'at.schmutterer.oss.gradle:gradle-openjpa:0.2.0'
'neva.openjpa'
and some more, but I just cannot enhance the class.
Of course I have goodled for quite some time. I am thankful for any idea I can follow...
Thanks in advance!
Just in case someone else has the same struggle. I have found a solution to this problem:
TomEE ships with JPA and everything that is needed. The eclipse "gradle buildship" plugin can be used to compile code. So the combination of the following components works perfectly fine for me:
apache-tomee-plus-7.0.2
tomcat v8.5 server (pointing to the apache-tommee installation)
Dynamic Web Project (using Dynamic Web Module 3.1)
Java Runtime Environment v1.8
The gradle script reduces simply to this:
apply plugin: 'war'
repositories {
mavenCentral()
}
dependencies {
providedCompile "javax:javaee-api:7.0"
}
I suppose it also works with TomEE 1.7.x and javaee-api:6.0, but I have not tried it.

How to configure Spring facet in IntelliJ IDEA

I'm new to Intellij 14.0 . I was using Netbeans, but my colleagues told me to shift to intellij and so I did.
I need to run the same project that I ran on netbeans in Intellij. The project that I'm working on is made of grails and spring. When I tried to run the project using Intellij this is what I get.
Spring Configuration Check
Unmapped Spring configuration files found.
Please configure/setup Spring facet for modules:
......... (1 file)
And this is the file.
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
<description>Grails application factory bean</description>
<property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
<property name="grailsResourceLoader" ref="grailsResourceLoader" />
</bean>
<bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
<description>A bean that manages Grails plugins</description>
<property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
<property name="application" ref="grailsApplication" />
</bean>
<bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
<constructor-arg>
<ref bean="grailsApplication" />
</constructor-arg>
<property name="pluginManager" ref="pluginManager" />
</bean>
<bean id="grailsResourceLoader" class="org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean" />
<bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
<property name="encoding">
<value>utf-8</value>
</property>
</bean>
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean" />
</beans>
Honestly, I dont have any idea how to fix it. Based on my understanding it is looking for some modules but I could not fix it. I even tried this "Add framework support" . But I couldn't find spring in the list.
Could you help me fix this? Thanks
Go to File/Project Structure/Modules, click the green plus icon, select Spring from the dropdown and select your module in the next dialog.
Then click the green plus in the right pane, click plus and select your Spring configuration files and classes and click OK.
Also take a look at IntelliJ Help for Spring Facet.
Just ran into this issue out of the blue today—my build was working last night, and this morning it stopped working—so I figured I'd post my solution using IntelliJIDE CE 2019.1.
Error Messages (to help people find this answer)
package org.springframework.transaction.annotation does not exist
package org.springframework.boot does not exist
Unknown facet type: 'Spring'
Unknown facet type: 'web'
Solution
Step 0:
Update IntelliJ
Menu: IntelliJIDE > Check for Updates (Mac OSX)
Step 1:
Clean out Maven repo and re-download dependencies to ensure that the sources are not corrupt. This will take 5+min.
$ cd [project_directory]
$ mvn dependency:purge-local-repository
Step 2:
Preform a clean install.
$ mvn clean install
Step 3:
Update IntelliJIDE's Repository Indexes:
Open IntelliJ Settings/Preferences
Build, Execution, Deployment > Build Tools > Maven > Repositories
Select repositories one by one (by clicking on the table row) and click the update button. Specifically, do it for https://repo.mave.apache.org/maven2. The download is ±700mb so it will take a while. (10+min)
Related Questions
getting package org.springframework.transaction.annotation does not exist error while packaging app
package org.springframework.boot does not exist
IntelliJ Ultimate 2018 - the manual way:
Menu File -> Project Structure
Right-click on your module and choose "Add..." -> Spring
Optionally click "fix" if spring is not listed as a dependency
Click the + icon at the top to add your spring configuration .xml file(s)
The automatic way:
Click the body of the popup notification
Click the "Create Default" option

Spring + ehcache + bigmemory go integration

I am integrating spring3.2 + ehcache + bigmemory go.
Firstly, i do not undertand what is the term "Save the BigMemory Go license-key file to the BigMemory Go home directory." What would be my BigMemory Go home directory in my java web application deployed on glassfish.
Request Help.
Secondly, i get this error:
nested exception is net.sf.ehcache.CacheException: Cannot instantiate enterprise features manager
Following is are my files;
<bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="/WEB-INF/ehcache.xml" />
<property name="shared" value="true" />
</bean>
Code:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" name="myBigMemoryGoConfig">
<diskStore path="C:/bigmemorygo"/>
<cache name="CACHE_GEN" maxBytesLocalHeap="124M" maxBytesLocalOffHeap="1G">
<persistence strategy="localRestartable"/>
</cache>
<cache name="CACHE_CMP" maxBytesLocalHeap="124M" maxBytesLocalOffHeap="1G">
<persistence strategy="localRestartable"/>
</cache>
</ehcache>
Help appreciated.
Thanks,
Godwin
For the BigMemory license, it just needs to be in your application classpath...2 ways to do this:
Copy the license file in your application's "WEB-INF/classes" folder (if using maven to build, that'd be in the /src/main/resources folder...)
Or, if you don't want to copy the license file in your application, add the JVM param "-Dcom.tc.productkey.path=" to your app server startup script (or JAVA_OPTS for example)
For the exception, might be related to the license...Please show us the exception stack if you can.
Hope that helps.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named xxx

Can't test a jpa/maven project. I have the error
"javax.persistence.PersistenceException: No Persistence provider for EntityManager named xxx"
when I run "mvn cleant test" from commandline. I have a Java SE project.
I have the persistence confiuration in 'src/test/resources/META-INF/persistence.xml'. And I also has the same for 'src/main/...'.
I can see the persistence.xml in 'target/classes/META-INF'. Only that is from the main, not from the test as I run the tests. This is not yet the problem, since both should work anyway.
Trying the JPA for the first time, but as I see, the files should be ok (location and content).
The persistence unit names should match also.
I'm using Eclipse (EE) with m2 and other necessary plugins, but running maven from commandline. I see no errors in the project.
// Update
Tried fixing the maven build as I noticed it should have the test classes and resources in 'target/test-classes'.
Changed the command to "mvn clean test-compile test"
Now the resources can be found from the correct place, but I still got the same error.
// update
For clarity here's the full persistence.xml
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="xxx"
transaction-type="RESOURCE_LOCAL">
<provider>my.package.EntityManagerFactoryHelper</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/db" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="yyy" />
<property name="javax.persistence.jdbc.password" value="zzz" />
<property name="eclipselink.ddl-generation" value="DROP_AND_CREATE" />
</properties>
</persistence-unit>
I took the helper example from other posts. Basically it just creates the emf using the 'xxx' persistence unit. Here's the helper class. http://pastebin.com/1GE6uMa1
Try to add < provider>org.hibernate.ejb.HibernatePersistence< /provider> inside tag
The provider has to be:
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
Else the table creation fails, even that there is no errors when creating the tables from the entities.
Spent about 2 days resolving this, since I thought I was pointed the right direction by the given hint and didn't check the provider then.
The provider has to be according to the eclipselink, as you could spot it in the configuration of the 'persistence.xml'.
But I failed to say it explicitly. Didn't know it would matter that much and it even succeeded with the table creation once. Not really sure what I had for the provider then, but it failed subsequently (after changes made to the table).
Probably there should had been other configurations by the provider.

Resources