How to install Hibernate 5 into Apache Karaf v4 - java

I've installed Apache Karaf v4.03 and queried the list of available features for Hibernate, as listed below. Unfortunately, I am using Hibernate v5.
hibernate | 3.3.2.GA | | Uninstalled | enterprise-4.0.3 | Hibernate 3.x JPA persistence engine support
hibernate | 4.2.15.Final | | Uninstalled | enterprise-4.0.3 | Hibernate 4.2.x JPA persistence engine support
hibernate-envers | 4.2.15.Final | | Uninstalled | enterprise-4.0.3 | Hibernate Envers 4.2.x
hibernate | 4.3.6.Final | | Uninstalled | enterprise-4.0.3 | Hibernate 4.3.x JPA persistence engine support
hibernate-envers | 4.3.6.Final | | Uninstalled | enterprise-4.0.3 | Hibernate Envers 4.3.x
hibernate-validator | 5.0.3.Final | | Uninstalled | enterprise-4.0.3 | Hibernate Validator support
I am unable to find instructions for installing Hibernate v5 into Karaf v4. Are there published instructions for performing this task, and perhaps a downloadable features file?

Latest hibernate-release comes Karaf ready already:
If you download the hibernate-release-5.0.5.Final.zip from hibernate's page (http://sourceforge.net/projects/hibernate/files/hibernate-orm/5.0.5.Final/hibernate-release-5.0.5.Final.zip/download) and decompress the file, you will see an osgi folder.
There you can find an already prepared feauture: hibernate-osgi-5.0.5.Final-karaf.xml.
You can just copy it to Karaf's deploy folder and then execute:
feature:install hibernate-orm
It should be installed without any problem.
Another way to install hibernate 5.0.5 feature is to add a repo to features with the command:
feature:repo-add command.
Here you can see the list of hibernate's features and the one I have installed:
karaf#root()> feature:list | grep hibernate
hibernate | 3.3.2.GA | | Uninstalled | enterprise-4.0.3 | Hibernate 3.x JPA persistence engine support
hibernate | 4.2.15.Final | | Uninstalled | enterprise-4.0.3 | Hibernate 4.2.x JPA persistence engine support
hibernate-envers | 4.2.15.Final | | Uninstalled | enterprise-4.0.3 | Hibernate Envers 4.2.x
hibernate | 4.3.6.Final | | Uninstalled | enterprise-4.0.3 | Hibernate 4.3.x JPA persistence engine support
hibernate-envers | 4.3.6.Final | | Uninstalled | enterprise-4.0.3 | Hibernate Envers 4.3.x
hibernate-validator | 5.0.3.Final | | Uninstalled | enterprise-4.0.3 | Hibernate Validator support
hibernate-orm | 5.0.5.Final | x | Started | hibernate-osgi | Combines all Hibernate core dependencies and requ
hibernate-envers | 5.0.5.Final | | Uninstalled | hibernate-osgi | Feature for easily adding Envers support to hiber
hibernate-infinispan | 5.0.5.Final | | Uninstalled | hibernate-osgi | Feature for easily adding Infinispan-based cachin
hibernate-ehcache | 5.0.5.Final | | Uninstalled | hibernate-osgi | Feature for easily adding Ehcache-based caching s
karaf#root()>

Run the following commands on Karaf shell to get Hibernate 5.1.0.Final working on Karaf 4.0.x:
feature:repo-add mvn:org.hibernate/hibernate-osgi/5.1.0.Final/xml/karaf
feature:install hibernate-orm

Hibernate 5 already provides a feature that is also available from maven central. Recent karaf versions provide a nice shortcut to install such features:
feature:repo-add hibernate 5.0.5.Final
feature:install hibernate-orm
So there is no need to manually download the hibernate zip.
If you build your own feature that needs hibernate 5 then you need to provide a element in it that points to the full hibernate feature url.
mvn:org.hibernate/hibernate-osgi/5.0.5.Final/xml/karaf

Related

How to undo a migration using Flyway?

I am working on a Spring project and I have FlyWay as a dependency to manage my migrations, I made a mistake on the SQL command. When I ran the project I got an error showing a problem with the script, a silly mistake that was easy to fix, I misspelled a column name. However, the undo command from the flyway is not working.
I was trying to undo a migration using FlyWay and I follow the tutorial from FlyWay documentation: link-flyway
However, I got this output:
C:\Users\leonardo.freitas\Documents\workspace\api>C:\Users\leonardo.freitas\Documents\workspace\flyway-9.8.1\flyway undo
A new version of Flyway is available
Upgrade to Flyway 9.8.2: https://rd.gt/2X0gakb
ERROR: The command 'undo' was not recognized. Make sure you have added 'flyway-proprietary' as a dependency.
Caused by: No command extension found to handle command: undo
That's my migration history:
C:\Users\leonardo.freitas\Documents\workspace\api>C:\Users\leonardo.freitas\Documents\workspace\flyway-9.8.1\flyway info
A new version of Flyway is available
Upgrade to Flyway 9.8.2: https://rd.gt/2X0gakb
Flyway Community Edition 9.8.1 by Redgate
See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#9.8.1
ERROR: Skipping filesystem location: sql (not found)
Database: jdbc:mysql://localhost:3306/volimed (MySQL 8.0)
Schema version: 5
+-----------+---------+----------------------------------------+------+---------------------+-----------------+----------+
| Category | Version | Description | Type | Installed On | State | Undoable |
C:\Users\leonardo.freitas\Documents\workspace\api>C:\Users\leonardo.freitas\Documents\workspace\flyway-9.8.1\flyway info
A new version of Flyway is available
Upgrade to Flyway 9.8.2: https://rd.gt/2X0gakb
Flyway Community Edition 9.8.1 by Redgate
See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#9.8.1
ERROR: Skipping filesystem location: sql (not found)
Database: jdbc:mysql://localhost:3306/volimed (MySQL 8.0)
Schema version: 5
+-----------+---------+----------------------------------------+------+---------------------+-----------------+----------+
| Category | Version | Description | Type | Installed On | State | Undoable |
+-----------+---------+----------------------------------------+------+---------------------+-----------------+----------+
| Versioned | 1 | create-table-medicos | SQL | 2022-11-19 03:12:19 | Future | No |
| Versioned | 2 | alter-table-medicos-add-telefone | SQL | 2022-11-19 13:32:45 | Future | No |
| Versioned | 3 | create-table-pacientes | SQL | 2022-11-19 13:46:17 | Future | No |
| Versioned | 4 | alter-table-medicos-add-column-active | SQL | 2022-11-19 15:28:46 | Future | No |
| Versioned | 5 | alter-table-paciente-add-column-active | SQL | 2022-11-19 15:45:28 | Failed (Future) | No |
+-----------+---------+----------------------------------------+------+---------------------+-----------------+----------+
And I want to redu the last migration.
Undo command is supported in both the Teams and Enterprise edition . Flyway Enterprise is the only version with auto generation of Undo scripts though. Bill, could you point me towards where the information is conflicting?
I find out a way to resolve this problem, I went to the FlyWay table and deleted the last row, when I ran the project the FlyWay applied the migration again.

How to force log4j to be used but not slf4j

EDIT: To clarify the question, I added many explanations.
In my project dependencies, I have both slf4j and log4j. This can't be changed for some technical reason.
>gradlew dependencies
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could
not be reused, use --status for details
> Task :dependencies
.
.
| | | +--- org.springframework.boot:spring-boot-starter-logging:2.5.7
| | | | +--- ch.qos.logback:logback-classic:1.2.7
| | | | | +--- ch.qos.logback:logback-core:1.2.7
| | | | | \--- org.slf4j:slf4j-api:1.7.32
| | | | +--- org.apache.logging.log4j:log4j-to-slf4j:2.14.1
| | | | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.32
| | | | | \--- org.apache.logging.log4j:log4j-api:2.14.1 -> 2.17.0
| | | | \--- org.slf4j:jul-to-slf4j:1.7.32
| | | | \--- org.slf4j:slf4j-api:1.7.32
.
.
+--- org.apache.logging.log4j:log4j-core:2.17.0
| \--- org.apache.logging.log4j:log4j-api:2.17.0
+--- org.apache.logging.log4j:log4j-api:2.17.0
BUILD SUCCESSFUL in 16s
1 actionable task: 1 executed
I want to set the log level in the code, and AFAIK that can only be done with log4j. As a result, I simply look for a way to make this code line (LogManager is part of log4j) returns log4j implementation and not slf4j implementation:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
.
.
private final Logger logger = LogManager.getLogger(getClass());
Sadly, the logger's class returns is org.apache.logging.slf4j.SLF4JLogger:
System.out.println("logger class is: [" + logger.getClass() + "]");
output:
logger class is: [class org.apache.logging.slf4j.SLF4JLogger]
Even though it sounds easy, I haven't been able to do it or find an example online. What can be done?
Log4j 2.x Core and the Log4j to SLF4J Adapter are two implementations of the Log4j 2.x API. If they are both present on the classpath log4j-to-slf4j is used. That is what happens in your case: messages logged using the Log4j 2.x API are sent to SLF4J, which sends them to Logback.
That is the standard logging configuration brought by the spring-boot-starter-logging. If you want to use Log4j 2 as backend instead you need to exclude that artifact and add spring-boot-starter-log4j2.
Anyway, since you are using Spring Boot, you have two ways to set the level of a logger:
Using Spring Boot's LoggingSystem abstraction (works for all available logging systems):
final LoggingSystem loggingSystem = LoggingSystem.get(getClass().getClassLoader());
loggingSystem.setLogLevel("loggerName", LogLevel.DEBUG);
Using the underlying logging system. In your case it is Logback, so you should use:
final Logger logger = LoggerFactory.getLogger("loggerName");
if (logger instanceof ch.qos.logback.classic.Logger) {
((ch.qos.logback.classic.Logger) logger).setLevel(Level.DEBUG);
}
Remark: due to recent vulnerabilities in both Log4j and Logback, you should bump your version of Spring Boot to 2.5.8 (or 2.6.2).
Whats the full class path of LogManager? It has to be imported, there you should see the full class.
My guess is that you need to change the Import to import some log4j LogManager, not the slf4j one.

Karaf - TransactionRequiredException

I am running Karaf, I have a DataSource in persistence.xml (pointing to a SQL Server DB), and I am trying to execute an insert query.
But I am getting this exception:
javax.persistence.TransactionRequiredException: Executing an update/delete query at
org.hibernate.jpa.spi.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:71)
My transaction-type is set to JTA.
I think I need to configure some transactions but I am not very familiar with this. I think it's something simple but I don't find many ideas when googling.
What do I need to change in my XML descriptors (persistence.xml or blueprints.xml)?
Please provide some sample XML snippet. Many thanks in advance.
71 | Active | 80 | 2.3.0 | Apache Aries JPA Container API
73 | Active | 80 | 2.3.0 | Apache Aries JPA container
74 | Active | 80 | 2.3.0 | Apache Aries JPA support
76 | Active | 80 | 1.1.1 | Apache Aries Transaction Blueprint
77 | Active | 80 | 2.1.0 | Apache Aries Transaction Blueprint
78 | Active | 80 | 1.3.0 | Apache Aries Transaction Manager
Take a look at the aries jpa examples. There are examples for blueprint and declarative services. For blueprint there is support for standard annotations like #PersistenceContext and #Transactional.
For DS you can use the JPATemplate to run code in a transaction and with an EntityManager.

Camel route with AMQP consumer runs ok in Eclipse, hangs in karaf

I am using Camel 2.17.3 and karaf 4.0.7 (also tried 4.0.1).
I have a Camel route that runs fine in Eclipse when a junit test starts it, but hangs when deployed to karaf. If I change the amqp: 'from' component to timer: the route runs fine in karaf.
My AMQP setup in the routebuilder is:
#Override
public void configure() throws Exception {
getContext().addComponent("amqp", AMQPComponent.amqpComponent(String.format("amqp://%s:%s?amqp.saslMechanisms=ANONYMOUS", AMQP_SERVICE_HOST, AMQP_SERVICE_PORT)));
Even this route will hang karaf, and run fine in Eclipse:
from("amqp:queue:myqueue").routeId("myRoute")
.log("temp")
In Karaf, when I say "hang", I observe these things:
If I try to exit karaf, it hangs - I need to kill the process.
If I try to stop the bundle, karaf hangs - I need to kill the process.
Neither camel:context-list nor camel:route-list return anything
I do not get a "route consuming from..." message in the log. This is all
the output from starting the bundle:
2016-10-08 23:46:00,593 | INFO | nsole user karaf | bundle
| 90 - org.apache.aries.spifly.dynamic.bundle - 1.0.1 | Bundle
Considered for SPI providers: mis-routes 2016-10-08 23:46:00,593 |
INFO | nsole user karaf | bundle | 90 -
org.apache.aries.spifly.dynamic.bundle - 1.0.1 | No 'SPI-Provider'
Manifest header. Skipping bundle: mis-routes 2016-10-08 23:46:05,595 |
INFO | ool-130-thread-1 | OsgiDefaultCamelContext | 56 -
org.apache.camel.camel-core - 2.17.3 | Apache Camel 2.17.3
(CamelContext: mis-routes) is starting 2016-10-08 23:46:05,599 | INFO
| ool-130-thread-1 | OsgiDefaultCamelContext | 56 -
org.apache.camel.camel-core - 2.17.3 | MDC logging is enabled on
CamelContext: mis-routes 2016-10-08 23:46:05,601 | INFO |
ool-130-thread-1 | ManagedManagementStrategy | 56 -
org.apache.camel.camel-core - 2.17.3 | JMX is enabled 2016-10-08
23:46:05,708 | INFO | ool-130-thread-1 |
DefaultRuntimeEndpointRegistry | 56 - org.apache.camel.camel-core -
2.17.3 | Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
2016-10-08 23:46:05,804 | INFO | ool-130-thread-1 |
OsgiDefaultCamelContext | 56 - org.apache.camel.camel-core -
2.17.3 | AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as
it may improve performance. 2016-10-08 23:46:05,805 | INFO |
ool-130-thread-1 | OsgiDefaultCamelContext | 56 -
org.apache.camel.camel-core - 2.17.3 | StreamCaching is not in use. If
using streams then its recommended to enable stream caching. See more
details at http://camel.apache.org/stream-caching.html
Any help would be hugely appreciated. Thanks!
The reason should be related to this issue in Camel JIRA: https://issues.apache.org/jira/browse/CAMEL-10278
The main problem is proton-j 0.10 is incompatible with qpid-jms-client version 0.8. We upgraded the dependency to proton-j 0.12.0 and the fix will be available in the Camel 2.17.4 release.
For the moment you can use Camel 2.17.4-SNAPSHOT or upgrade the dependency in the Camel-Amqp Karaf feature.

PDFRenderer.jar version

I have a project which uses PDFRenderer.jar v1.0.5 which was probably downloaded from http://grepcode.com/snapshot/repo1.maven.org/maven2/org.swinglabs/pdf-renderer/1.0.5
A quick google search finds the PDFRenderer.jar in a project at https://java.net/projects/pdf-renderer/downloads which shows v0.9.1 as the latest version
version | last-modified | Ant version | # of objects in com.sun.pdfview
-----------------------------------------------------------------------
1.0.5 | 2009-03-15 | 1.7.1 | 82
0.9.1 | 2011-09-15 | 1.8.2 | 91
The problem is that the 0.9.1 version has a more recent last-modified date, and has more objects in the com.sun.pdfview package than the 1.0.5 version.
Does anyone know which one is the most recent version?
don't go through version number because jar provider are different, go through last-modified date.

Categories