No query defined for that name
No query defined for that name
hibernate returning a «No query defined for that name» error when using «jar-file» property
I have my war application which uses entities defined in multiple jar files. In my persistence.xml I have defined one jar-file tag for each one of those jars, but the entities contained in those jars are not loaded when the application starts. If I specify each class using the «class» tag everything works fine.
I’m sure that the relative path defined for those jars is correct, because if I change it I get the error: «HHH10000002: File or directory named by URL [vfs. ] could not be found»
This is my persistence.xml :
Am I missing something? The log does not contain any error or warning, it looks like the entities are simply ignored.
1 Answer 1
Try to correct your persistence.xml in the following way:
As it’s stated in the 8.2.1.6.3 Jar Files section of the JPA 2.2 specification:
One or more JAR files may be specified using the jar-file elements instead of, or in addition to the mapping files specified in the mapping-file elements. If specified, these JAR files will be searched for managed persistence classes, and any mapping metadata annotations found on them will be processed, or they will be mapped using the mapping annotation defaults defined by this specification. Such JAR files are specified relative to the directory or jar file that contains[91] the root of the persistence unit.[92]
[91] This semantics applies to persistence.xml files written to the persistence_2_0.xsd or later schema. Due to ambiguity in the Java Persistence 1.0 specification, provider-specific interpretation of the relative references used by this element may apply to earlier versions.
[92] Persistence providers are encouraged to support this syntax for use in Java SE environments
Static Final
Architecture, Enterprise Java, JavaFX, and the Netbeans RCP
Camel
Using Apache Camel and ActiveMQ to Implement Synchronous Request/Response.
Implementing a synchronous request/response pattern with Apache Camel and ActiveMQ is quite a bit easier than you may expected, and has allowed us to leverage our current messaging infrastructure to facilitate synchronous exchanges between applications where we otherwise may have needed to create a new web service.
Below is an example of setting up two Camel endpoints which will demonstrate the request/response pattern.
First, configure the connection to the JMS message broker. In this case, an ActiveMQ broker is created in-process.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Next, set up the producer route. First a processor is created, which will print the body of the message. The route will be executed when a file is dropped into the /Users/RobTerpilowski/tmp/in directory, and routed to the robt.test.queue destination. Once the route has completed, the processor will be executed. What we are hoping to see is that the message has been modified by the consuming endpoint when this route has completed. The important piece to note here is the url:
jms-broker:queue:robt.test.queue?exchangePattern=InOut
exchangePattern=InOut tells Camel that the route is a syncrhonous request/response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Next, set up the consumer endpoint. Again, a processor is created which will be run when the route has completed. This processor will first print the message that the producer sent. It will then replace the message with a new message saying that the original message was seen. This endpoint will listen on the robt.test.queue and route the result to the directory /Users/RobTerpilowski/tmp/out. When the route has completed, the processor will update the message. If everything works correctly, the producer endpoint should be able to see the modified message.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
So now that the routes are set up, it’s time to send a message. Saving a file in the specified input directory will kick things off. The file will contain the text “HelloCamel”.
The consumer listening on the robt.test.queue immediately sees the message arrives, and prints the message body.
The producer endpoint then receives the modified message back, with confirmation that the consumer endpoint did indeed see the message.
Make Sure Your Server Clocks are in Sync!
As I finished my first test services that would utilize the Request/Response pattern I created an integration test where they connected to messaging broker that was running in-process. Things looked great, and the services were communicating without any issues. I deployed the services to a Wildfly instance running locally, which were pointing at a messaging broker on our staging server. However, this time when I started my test, the requests were consistently timing out, and never making it back from the second service. I literally spent the entire day deconstructing each service piece by piece to see what was going on. I then remembered something about clock synchronization in the Camel JMS documentation. I checked both the clock on the VM and the clock on the staging server and proceeded to do a face palm when I saw there was a four hour difference, lesson learned!
JPA java.lang.IllegalArgumentException: No query defined for that name (Solved)
I’ve recently been working with the [Camel JPA] (http://camel.apache.org/jpa.html) component for moving data from one of our SQL servers to our messaging system.
We have a number of Entity POJOs defined that contain a named query which the JPA component uses in order to query the database to select the appropriate records that need to be processed. Everything was working great and I decided to move these beans to a separate library that could be shared with other applications. However, once I did this the original application started encountering the following error.
I checked the classpath and the beans were in fact being found, but the named queries on the beans were not being found. It took some research, but the solution to the problem ended up proving to be very simple.
The change was to explicitly add the entity classes to the application’s persistance.xml
Monitoring Real-Time Commodity Prices using JavaFX, NetBeans RCP, and Camel
Zoi Capital is a commodity investment firm which trades in the commodity futures markets on behalf of clients, with offices in New York and Seattle. We needed an application which could display the commodities we were currently holding as well as show any open profit/loss of our trades in real-time. In addition, we wanted to display the current performance of our trading strategy (named Telio) along with a comparison of the current performance of the S&P 500 stock index as well as the Dow Jones UBS commodity index.
Trades are placed from the Seattle office, but are monitored throughout the day from the New York office, so the application (which would be running in New York) needed a way to stay up to date with the current trades. The application also needed to be aesthetically pleasing as it was planned to put it on a large 50 inch LCD in the reception area of our New York office, where both staff and visitors could view the current trades and statistics in real time.
I had previously written an automated trading application on the NetBeans Rich Client Platform (RCP), where I had created a number of plug-ins, including a plug-in to connect to Interactive Brokers to retrieve real-time market data. Since I already had the plug-ins available in order to connect to a real-time data feed, it seemed a natural choice to also build the Quote Monitor application on the NetBeans RCP as well. Instead of using the existing Swing components however, I opted for JavaFX in order to give the application a polished look.
In order to get the trade information from the Seattle office to the Commodity Monitor application in the New York office, we made use of Camel to facilitate the communication between the 2 offices. The great thing about Camel is that it provides an abstraction layer for the actual communication mechanism between applications. Since the offices are not networked together we made use of the Camel email component in order to transfer the data from the Seattle office to the Commodity Monitor application. In the future we could move the communication mechanism to web services or JMS simply by changing a property file, with no code changes required as camel takes care of everything else under the hood.
System Architecture
Trades are placed in the Seattle office, and then emailed to a designated email box which the Commodity Monitor watches (via Camel). Trade information is then imported into the application, at which point it requests real-time quote information of the commodities from Interactive Brokers via their Java API. At this point the application can then update the profit/loss statistics in real-time.
Application Screen Shot
The grid in the top left portion of the screen displays the performance for our Telio trading strategy for today, for the month of August, and then the year-to-date return of the strategy. The table also shows the same statistics for the S&P 500 stock index and Dow Jones/UBS commodity index for comparison purposes.
Below the table is a candlestick chart displaying the performance of the S&P 500 Index futures for the current day. The chart made use of the charting API in JavaFX as well as CSS. The chart is updated in real-time throughout the day.
Finally, on the right half of the screen is a panel which displays the commodities that we are currently holding with current profit/loss on the trade. For example, we have a current profit of +0.18% since we bought natural gas.
To add additional eye candy to the application, I created a scrolling background with a slightly blurred Zoi Capital logo. The animation was extremely easy to set up in JavaFX, and I’ll post a short how-to blog on animations in the not-too-distant future.
Demo Video
Below is a 3 minute video demo showing the Commodity Monitor application with the animated scrolling background. About 40 seconds into the video an email is sent to the Camel email box, at which point the Commodity Monitor picks up the email and displays the commodities that were sent, and their corresponding profit/loss in real time. Another email is sent at the 2:10 mark that clears most of the commodities from the application.
Writing to a NoSQL DB using Camel
We use a somewhat out of the ordinary NoSQL database called “Universe“, produced by a company called Rocket as our primary data store. We have written our own ORM framework to write data to the DB from Java beans that we have dubbed “siesta” as it is a lightweight hibernate-like framework.
Camel is a great framework for implementing Enterprise Integration Patterns (EIP), and we have started making heavy use of the various Camel components in order to pass data in varying formats between internal and 3rd party systems.
While there are large number of components available out of the box available here, there are no components available for writing data to UniVerse
Fortunately it is extremely easy to implement custom Camel components, and we were able to create a component to write to UniVerse with a few classes and one configuration file.
For the Camel endpoint URI, we would like to use the following format:
siesta:// denotes the component scheme,
com.lynden.siesta.component.FreightBean denotes the annotated POJO that the Siesta framework will use to persist the data to UniVerse.
uvSessionName=XDOCK_SHARED tells the component which database session pool to use when connecting to the DB.
The Endpoint Class
The Component Class
The next step is to create a class to represent the component itself. The easiest way to do this is to extend the org.apache.camel.impl.DefaultComponent class and override the createEndpoint() method.
The createEndpoint method takes as arguments, the uri of the component, the path, which includes the “com.lynden.siesta.component.FreightBean” portion of the URI, and finally the options, which include everything after the “?” portion of the URI.
From this method we use reflection to load the BaseBean class specified in the URI, and pass it into the SiestaEndpoint class that was created in the previous step.
The Producer Class
The Config File
The META-INF/services/org/apache/camel/component/siesta file contains 1 line to tell the Camel Context which class to load:
That’s it, With 3 relatively simple classes and a small config file we were able to easily implement our own Camel producer using our NoSQL database as an endpoint.
CamelOne 2012 Summary
I’ve just returned from the CamelOne Open Source Integration Conference in Boston where I was invited as a speaker to present how Lynden is using ActiveMQ as part of its freight tracking infrastructure. As expected, there were a number of big announcements and very interesting projects that speakers from all over the world showcased during the 2 day conference. Here are few new projects/applications that I found may be useful here at Lynden in particular.
We are currently only running 1 production message broker, but we have 8 message brokers in our test environment. Fuse Fabric could greatly reduce the overhead of managing the configuration of those brokers.
Apache ZooKeeper
As it seems at these conferences, there are always ideas flying around among the attendees and I always seem to obtain just as many new ideas attending sessions as I do talking to other architects and developers outside the sessions. I was explaining to someone the challenge we have with managing the configurations of our 70+ web applications and services in our production, staging and test environments. His immediate response was to take a look at Apache ZooKeeper. They had been using it the past few months for managing configuration of multiple environments with good success. As mentioned above, Fuse Fabric makes use of Apache ZooKeeper, and I’m curious to learn if Fabric can be used beyond the integration apps it mentions (ESB, MQ, etc), and also used for things such as our web applications and services.
Fuse Management Console
Provides a toolf for managing large-scale deployments of Fuse ESB Enterprise and Fuse MQ Enterprise. A FuseSource subscription is required to install the console, which provides the following benefits:
MQTT protocol support in ActiveMQ 5.6
MQTT protocol has come a little late for Lynden since we already have a solution for connecting Windows CE devices to ActiveMQ. MQ Telemetry Transport (MQTT) is a machine to machine protocol design as an extremely lightweight publish/subscribe messaging transport. ActiveMQ 5.6 and Apollo 1.0 will both support MQTT.
Fuse HQ
Fuse HQ is a SOA management and monitoring system and is available with a FuseSource support subscription. Fuse HQ takes advantage of the JMX-based reporting capabilities of the Fuse products. Some of the features Fuse HQ provides are:
Monitor systems– comprehensive cross-stack dashboard make it easy to check the health of systems and services
Manage systems– execute control operations to manage the FuseSource environment
Intelligent Alerts– definable alerts proactively identify problems before they occur
Documentation
System check framework¶
The system check framework is a set of static checks for validating Django projects. It detects common problems and provides hints for how to fix them. The framework is extensible so you can easily add your own checks.
API reference¶
CheckMessage ¶
Constructor arguments are:
There are subclasses to make creating messages with common levels easier. When using them you can omit the level argument because it is implied by the class name.
Builtin tags¶
Django’s system checks are organized using the following tags:
Some checks may be registered with multiple tags.
The sites tag was added.
The files tag was added.
Core system checks¶
Asynchronous support¶
The following checks verify your setup for Asynchronous support :
Backwards compatibility¶
Compatibility checks warn of potential problems that might occur after upgrading Django.
Caches¶
The following checks verify that your CACHES setting is correctly configured:
Database¶
MySQL and MariaDB¶
If you’re using MySQL or MariaDB, the following checks will be performed:
Managing files¶
The following checks verify your setup for Managing files :
Model fields¶
File fields¶
Related fields¶
Models¶
Security¶
The security checks do not make your site secure. They do not audit code, do intrusion detection, or do anything particularly complex. Rather, they help perform an automated, low-hanging-fruit checklist, that can help you to improve your site’s security.
The following checks verify that your security-related settings are correctly configured:
Signals¶
Templates¶
The following checks verify that your TEMPLATES setting is correctly configured:
Translation¶
The following checks are performed on your translation configuration:
The following checks are performed on your URL configuration:
contrib app checks¶
admin ¶
Admin checks are all performed as part of the admin tag.
The following checks are performed on any ModelAdmin (or subclass) that is registered with the admin site:
ModelAdmin ¶
The following checks are performed on any ModelAdmin that is registered with the admin site:
InlineModelAdmin ¶
GenericInlineModelAdmin ¶
AdminSite ¶
The following checks are performed on the default AdminSite :
contenttypes ¶
The following checks are performed when a model contains a GenericForeignKey or GenericRelation :
postgres ¶
The following checks are performed on django.contrib.postgres model fields:
sites ¶
The following checks are performed on any model using a CurrentSiteManager :
What is the difference between hibernate session’s getNamedQuery(String name) and createNamedQuery(String name)?
I am developing an application using Spring and Hibernate. I am wondering why there are two separate methods getNamedQuery(String name) and createNamedQuery(String name).
I checked Javadoc here and found the description to be similar except createNamedQuery accepts native sql (there’re separate methods createNativeQuery, getNamedNativeQuery, getNamedSQLQuery to create native queries).
I want to understand whether there is any other fundamental difference that makes my queries faster/slower.
1 Answer 1
TL;DR
The two methods perform (except some minor things) the same processings : try to execute a named JPQL or SQL query with the almost same logic.
Your remark is good as the javadoc of these methods should be almost the same while these differ.
Query getNamedQuery(String queryName);
Create a Query instance for the named query.
Parameters:
queryName the name of a pre-defined, named query
Query createNamedQuery(String name);
The JPA-defined named query creation method. This form can represent an HQL/JPQL query or a native query.
Parameters:
name the name of a pre-defined, named query
It gives the feeling that getNamedQuery() may not process any kind of query.
For this kind of question, the best way to understand the difference is very often looking into the method implementations.
Implementation of these methods are located in the org.hibernate.internal.AbstractSharedSessionContract class.
We could see here createNamedQuery() that relies on buildQueryFromName() :
And we could see there getNamedQuery() that performs itself what buildQueryFromName() does for createNamedQuery() :
Static Final
Architecture, Enterprise Java, JavaFX, and the Netbeans RCP
Formatting Rows in a JavaFX TableView Using CSS Pseudo Classes
One strategy for formatting cells in a JavaFX TableView is to utilize CSS Pseudo classes and a TableRowFactory to select the appropriate class to style the row. Below is a screenshot of an applcation that is configured to monitor real time stock quotes. Each row displays price information for a single stock. I would like the rows to be colored based on the price change of the particular stock, with a red row representing a stock that is trading lower since the previous day, and a green row to represent a stock whose current price is higher than the previous day.
First the domain object which represents the Stock is below. Notice that the class uses JavaFX properties to represent the various values that are displayed in each column.
Ok, so far this seems easy enough. Now the tricky part is to activate the proper Pseudo class when the % change of the stock price is positive or negative. This can be done using a TableRowFactory in the controller class which is managing the TableView.
Below is an example controller which has a reference to a TableView object called tickerTableView. The setup() method contains logic for selecting the appropriate pseudo class based on the stock data.
The first step is to create 2 new PseudoClass object which will map to the Pseudo classes that were defined in the css file.
Next a RowFactory needs to be defined which knows how to select the proper PseudoClass. The setRowFactory() method on the TableView class takes a Callback object which in turn takes a TableView as an argument and returns a TableRow.
The first thing to do in the row factory is to create a new change listener. This listener will monitor the stock for a particular row. The oldPrice and newPrice are passed into the change listener. The pseudo class of the row can then be activated or deactivated by invoking the pseudoClassStateChanged() method on the TableRow and passing the appropriate PseudoClass and boolean value to indicate whether or not the class should be active.
The final piece is to tie the change listener to the item in the TableRow. This is done by adding a listener on the ItemProperty of the row. Once a Stock item is added to the TableRow, the ChangeListener defined above can be bound to the Stock’s percentChangeProperty. The initial state of the classes are also set when the new item is added. If a Stock item is being removed from the TableRow, the previousStock variable will be populate with the Stock object that is being removed. At this point the change listener can be removed from the row for the old Stock before the new one is added.
The final result is displayed in the table below Rows will change between red and green automatically in real time as the price of the stock fluctuates throughout the trading day.