Open ObjectDB explorer whilst running the tomcat server / instance - java

I'm new to ObjectDB and not sure if I've done something wrong here but I'm getting a couple of issues I'm hoping the community can help me with.
First is this annoying inability to view the db in the explorer when the server is running. If the explorer is open first then the tomcat/server/idea will crash and burn.
I get this:
If on the other hand Explorer is open and I try to restart the server :
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.objectdb.o._PersistenceException: Attempt to open a database file '/Users/SteveGreen/Development/Dev Workspace/RatedPlate_Java/RatedPlate/target/RatedPlate/WEB-INF/db/ratedplate.odb' that is currently in use by another process
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
I then need to close connection in explorer and restart the server, however the saga continues as now I receive:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.objectdb.o._PersistenceException: Attempt to open a database file '/Users/SteveGreen/Development/Dev Workspace/RatedPlate_Java/RatedPlate/target/RatedPlate/WEB-INF/db/ratedplate.odb' with an old unsupported format
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
and I need to clean install the mV build before continuing again.
I'm using version 2.2.5 as per the pom, the explorer is from version 2.6.3 as the earlier jar that I downloaded that mapped to my version was not displaying the query option. If I suggest to the IDE that I now use a version other than 2.2.5 then all hell breaks loose and I'm not sure what the best course of action is. As you can imagine, it makes for a pretty shitty debug environment.
Any help is hugely appreciated, thanks!
From my pom:
com.objectdb
objectdb
2.2.5
Persistence:
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="RatedPlateDB" transaction-type="RESOURCE_LOCAL">
<provider>com.objectdb.jpa.Provider</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="$objectdb/db/ratedplate.odb"/>
<property name="javax.persistence.jdbc.user" value="admin"/>
<property name="javax.persistence.jdbc.password" value="admin"/>
</properties>
</persistence-unit>
EDIT: I believe I've found and fixed the upgrade issue - 2.6.3 does not come with Jta or persistence
details: http://m2.objectdb.com
Updated pom:
<dependency>
<groupId>com.objectdb</groupId>
<artifactId>objectdb</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>

In embedded mode the database file is locked by one process, so you cannot access the same database (in embedded mode) concurrently in the Explorer and in your application.
To access a database by more than one process at the same time use either client-server mode or embedded-server mode.

Related

Register additional persistence unit in Keycloak Quarkus

We have a custom keyloak user storage provide to use our proprietary user database for authentication.
This works perfectly fine with the WildFly based Keycloak. Since Keycloak will drop WildFly support in june 2022 according to their release notes, I am currently trying to get it running in the new, Quarkus based Keycloak distribution.
First I had to remove all dependencies provided by Quarkus since those lead to class loader issues. But now I am stuck with this error when I try to start Keycloak with the command ./kc.sh start-dev --log-level=ERROR:
Updating the configuration and installing your custom providers, if any. Please wait.
ERROR: Unexpected error when starting the server in (development) mode
ERROR: Failed to start quarkus
ERROR: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
ERROR: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
For more details run the same command passing the '--verbose' option. Also you can use '--help' to see the details about the usage of the particular command.
And 'hibernate.dialect' is set in persistence.xml and configuring a persistance unit in persistence.xml should be supported according to quarkus documentation :
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="example-pu" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.example.keycloak.provider.db.entity.Benutzer</class>
<class>com.example.keycloak.provider.db.entity.BenutzerWithSource</class>
<class>com.example.keycloak.provider.db.entity.Rolle</class>
<class>com.example.keycloak.provider.db.entity.Parameter</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
</properties>
</persistence-unit>
</persistence>
Configuring the dialect in an application.properties (according to https://quarkus.io/guides/hibernate-orm#multiple-persistence-units) file in the delivery didn't change the behavior as well:
quarkus.hibernate-orm."example-pu".hibernate-dialect=org.hibernate.dialect.OracleDialect
What am I missing?
Additional Persistence Units are not supported in Keycloak 17.0.0 with Quarkus.
This should be fixed in Keycloak 18.0.0: https://github.com/keycloak/keycloak/pull/10581.

Tomcat classpath loader javax.mail.Session conflict with spring-boot-starter-mail

Trying to deploy a Spring Boot app on Tomcat (not the embedded Tomcat). I have configured a Java mail session on the Tomcat server config, and I'm trying to access it as a JNDI value in my app. For some reason, my app gets an error and shows this:
Caused by: java.lang.IllegalArgumentException: The local resource link [support] that refers to global resource [mail/support] was expected to return an instance of [javax.mail.Session] but returned an instance of [javax.mail.Session]
at org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:163)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:840)
I have included javax.mail.jar in the Tomcat /lib folder. I also have spring-boot-starter-mail included in my pom.xml
I've tried removing the javax.mail.jar from Tomcat's lib, but that causes an error on Tomcat start because it can't create the mail session. I've also tried removing spring-boot-starter-mail, but that interferes with some of my code that requires JavaMailSender and other mail components. I've tried messing with the JNDI import and stuff like that, but to no avail. I've also tried checking the version of the mail jar included by spring-boot-starter-mail, and updating the jar in Tomcat to match. I've also checked my transitive dependencies in Maven to see if a different mail implementation is being pulled in, and there's nothing. So I'm kind of all out of ideas.
Here's where I'm getting the JNDI value in my web.xml:
<resource-ref>
<description>The mail session configured in Tomcat</description>
<res-ref-name>mail/support</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Here's what I have configured in Tomcat's server.xml:
<GlobalNamingResources>
<Resource name="mail/support"
auth="Container"
type="javax.mail.Session"
mail.smtp.host="smtp.XXX.XXX"
mail.smtp.user="support"
mail.smtp.from="support#XXX.org" />
</GlobalNamingResources>
And here's what's in context.xml:
<Context>
<ResourceLink global="mail/support" name="mail/support" type="javax.mail.Session" />
</Context>
I'd like to be able to use spring-boot-starter-mail, and use a globally configured JNDI mail session. I don't know if those are just incompatible wishes, but I don't see why they should be.
Ok, so the solution was indeed what #Bill Shannon suggested. I had to include the com.sun.mail dependency with the Maven provided scope. My particular issue was that the project was already using the spring-boot-starter-mail dependency, which includes the com.sun.mail jar. So I had to exclude that from my Maven dependency. So the complete Maven dependency related to mail stuff looks like this:
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<exclusions>
<exclusion>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</exclusion>
</exclusions>
</dependency>
That seems a little obvious now. I think my main source of confusion was the weird Tomcat error message. Thanks for anyone who took a look at this, hopefully this resolves the issue for someone else!

Why we are getting exception when we enable the query-cache in hibernate.cfg.xml file by use hibernate 5.3.1.Final dependency?

I created a small second level cache program by using 'hibernate 5.3.1.final' dependency.I used below dependencies to work with Second level cache.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.3.1.Final</version>
</dependency>
In this dependency the 'EhcacheRegionFactory' package name was changed.so we need to use like below property in our 'hibernate.cfg.xml'file.
<property name="hibernate.cache.region.factory_class">
org.hibernate.cache.ehcache.internal.EhcacheRegionFactory
</property>
In hibernate 5.3 the second level cache is working fine but 'query-cache' is not working.i am getting below exception when iam enabling the query-cache in 'hibernate.cfg.xml'.
->Exception in thread "main" java.lang.ExceptionInInitializerError
->Caused by: org.hibernate.service.spi.ServiceException: Unable to create
requested service [org.hibernate.cache.spi.CacheImplementor]
->Caused by: org.hibernate.cache.CacheException: On-the-fly creation of
JCache Cache objects is not supported
[org.hibernate.cache.spi.TimestampsRegion]
How to solve this one?
But The same program when i tried with hibernate 5.2.17 dependency the query cache working fine.
Use Hibernate ORM Hibernate Core ยป 5.3.4.Final dependencies it will work

While adding <provider> to Persistance.xml it' showing "Invalid content was found starting with element 'provider'."

I am trying to add to my persistance.xml file.
Like Below:
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
When I added to my persistance.xml it's showing
Invalid content was found starting with element 'provider'
How can I overcome this
I have added 2 jars
1.eclipselink.jar
2.javax.persistence_2.0.4.v201112200901.jar
Try to use
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
With this pom.xml
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0</version>
I think you're looking at older version of persistence.xml definition. The <provider> element is no longer valid on the java ee 6, check the persistence.xml xsd.
So try either using the latest persistence.xml schema or downgrading your java ee environment.

Seed data import failed on jboss-javaee6-webapp

I am trying to get a basic Seam 3 webapplication to work and use the jboss-javaee6-webapp to achieve this goal. Using the manual at http://seamframework.org/Documentation/CDIQuickstartForMavenUsers.
However, I am running into some problems which I haven't been able to solve for days. I have basically no experience in JavaEE so the solution is probably really easy.
What I've done? I've simply generated a new maven project based on the supplied archetype and didn't change anything about it. I've installed Eclipse Helios including JBoss Tools and downloaded JBoss 6.0.0 and got Eclipse to deploy the application to the server succesfully.
While deploying, an exception occurs in the example code. To be specific the following exceptions occurs:
09:29:20,712 WARN [seam3-example] Seed data import failed.: java.lang.NullPointerException
at org.jboss.weld.integration.persistence.JBossJpaServices.resolvePersistenceContext(JBossJpaServices.java:59) [:6.0.0.Final]
at org.jboss.weld.util.Beans.injectEEFields(Beans.java:781) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1$1.proceed(ManagedBean.java:181) [:6.0.0.Final]
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:54) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1.work(ManagedBean.java:176) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean$FixInjectionPoint.run(ManagedBean.java:142) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.inject(ManagedBean.java:170) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:339) [:6.0.0.Final]
at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:67) [:6.0.0.Final]
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:669) [:6.0.0.Final]
at org.jboss.weld.bean.AbstractReceiverBean.getReceiver(AbstractReceiverBean.java:84) [:6.0.0.Final]
at org.jboss.weld.bean.ProducerField$1.produce(ProducerField.java:134) [:6.0.0.Final]
at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:361) [:6.0.0.Final]
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.createUnderlying(EEResourceProducerField.java:170) [:6.0.0.Final]
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.access$000(EEResourceProducerField.java:54) [:6.0.0.Final]
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField$EEResourceCallable.call(EEResourceProducerField.java:80) [:6.0.0.Final]
at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:50) [:6.0.0.Final]
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62) [:6.0.0.Final]
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125) [:6.0.0.Final]
at org.jboss.weldx.persistence.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$Users$sander$Workspaces$eclipse$web-dev-32$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1306911969901$deploy$seam3-example$war"-ProducerField-nl$jdi$examples$data$MemberRepositoryProducer$em_$$_WeldProxy.persist(org$jboss$weld$bean-jboss$classloader:id="vfs:$$$Users$sander$Workspaces$eclipse$web-dev-32$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1306911969901$deploy$seam3-example$war"-ProducerField-nl$jdi$examples$data$MemberRepositoryProducer$em_$$_WeldProxy.java)
at nl.jdi.examples.data.SeedDataImporter.importData(SeedDataImporter.java:51) [:]
...
I've searched for a solution for this exact exception but I could barely find anything about it. This probably means that I've overlooked something very simple. So I've analysed the exception and found the following:
The exception message is from the example code (SeedDataImporter.java:61)
The exception itself (NullPointer) is thrown somewhere in the weld code
The problem seems to be purely persistence related (it can't find the PersistenceContext?)
Since the problem is persistence related, I've tried to change the persistence.xml however this didn't pay out. I think the problem is within the JDNI/Persistence.xml/Server config domain, however I can't be sure.
Can anybody point me in the right direction?
persistence.xml
<?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="primary">
<jta-data-source>jdbc/__default</jta-data-source>
<properties>
<!-- Properties for Hibernate (default provider for JBoss AS) -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<!-- Properties for EclipseLink (default provider for GlassFish) -->
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="FINE" />
</properties>
</persistence-unit>
Edit:
When I try to deploy the unchanged application to GlassFish 3.1 within Eclipse I get the following error:
cannot Deploy seam3-example
Deployment Error for module: seam3-example: Error occurred during deployment: Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton SeedDataImporter. Please see server.log for more details.
Cannot create tables for application seam3-example. The expected DDL file seam3-example_primary_createDDL.jdbc is not available.
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.
I think it is a persistance.xml problem because you have:
<jta-data-source>jdbc/__default</jta-data-source>
and this is default for Glassfish AS
Try this:
<jta-data-source>java:/DefaultDS</jta-data-source>
This is default for JBoss
Do you run JBoss AS in default domain?
If you check the persistence.xml file generated by the archetype, you'll see this comment:
<!-- A matching data source is added to JBoss AS by deploying the project file default-ds.xml -->
<jta-data-source>jdbc/__default</jta-data-source>
Inside resources-jbossas there's a default-ds.xml file that you should deploy to JBoss in order to be able to use the app without any code changes.
At least on the command line I can start the example doing this:
Download and install the latest jboss 6 to
mvn archetype:generate -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.1.CR1 -DarchetypeRepository=central -DgroupId=com.example -DartifactId=jee-example -Dversion=0.0.1-SNAPSHOT
cd jee-example
mvn clean package jboss:hard-deploy -Djboss.home=<jboss-6.0.0.Final>
start the jboss with <jboss-6.0.0.Final>/bin/run.sh (run.bat on Windws)
open http://localhost:8080/jee-example/
For more details have a look at the readme.html that is created by the archtype in the same folder as the pom.xml
To work in eclipse you should install
eclipse for Java EE Developers
m2eclipse from this update site
m2eclipse wtp extension from the m2eclipse-extra update site documentation
I did not try the eclipse part for the archetype...

Categories