EclipseLink and GlassFish: initial DDL creation - sql

I try to use Flyway to update my databases. In order to setup Flyway I need to get the current DDL. Normaly one would use EclipseLinks schema generation mechanism by configuring:
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="sql-script" />
But I am unable to get this working using a GlassFish 3.1.2.
Is there any possibility to achieve what I want, or am I on the wrong track?

Glassfish overrides the eclipselink DDL properties for its own DDL generation feature described here http://docs.oracle.com/cd/E18930_01/html/821-2418/gbwlh.html
It will force writing out scripts that it then uses to create tables, and drop them if required. I don't have the location it has them written to, but check if you can control it through glassfish. Otherwise, try specifying the "eclipselink.create-ddl-jdbc-file-name" property to define the file name and location it ahold be written to. You can also access the persistence unit in a simple java main class outside glassfish if you need the script just once and want to store it with the persistence unit.

Related

Per Infinispan Cache Properties

We have some generic code that operates on the caches in an Infinispan cache container. The code identifies certain caches for which a certain operation has to be performed by a custom property. The cache container and caches are configured through infinspan.xml or the Infinispan subsystem in WildFly.
Previously we would set a custom property on the datastore of the cache. With Infinispan 10+ this is no longer possible. We would have to implement a custom persistence store in order to set arbitrary properties on a cache. This seems like overkill especially since our caches are not persistent.
Is there a way to achieve this from an infinspan.xml, eg. without putting a custom object under a well known key in the cache?
Edit
The previous configuration looked something like this:
<local-cache name="stackoverflow-cache" configuration="default-configuration">
<data-container>
<property name="custom-property-key">custom-property-value</property>
</data-container>
</local-cache>
With version 10 of the Infinispan schema this is no longer supported.
I've made an example of how you can set some custom properties in the configuration here. It isn't trivial...
If you are using Infinispan server, you need a Jar with your classes and put it in server/lib folder.
Let me know if it fits your use case (I hope I didn't misunderstand it).
ps. since you control the parser, you can set your own XML structure if you want.

Is there any way to have different configurations for different databases in dbUnit / Arquillian Persistence extension?

I am trying to make integration tests that access the database using Arquillian Persistence Extension / DBunit.
It works well and I have this configured to test the part of the system that access MySQL:
<extension qualifier="persistence-dbunit">
<property name="qualifiedTableNames">true</property>
<property name="escapePattern">`?`</property>
</extension>
The escapePattern is important because I have tables with names like "user", "key" and so on.
Now I want to test the part of the system that access Vertica. Vertica has a different escape character (") and does not recognize ` as escape. Every time I try to run the test, I get an error due to the ``.
Is there any way to have two different configurations which are activated depending on which test is ran? (Or which database connection is used)?
The limitation of APE (Arquillian Persistence Extension) at the moment is that it cannot control more than one database from within a single test. I understand that your case is different, you would like to run different suites of tests against different databases (or even the same tests against different databases but with different configuration). I solved it for APE using maven profiles and I test the code base against several different combinations of containers and databases (there is docker involved in-between which you will see in the referenced example, but that's not really important for this). My approach simply boils to following:
I have separated test-resource folders for every configuration
In there I have dedicated arquillian.xml configs relevant for given DB
Maven profiles and adding those special test-resource folders on demand
This way I keep the tests portable, but I can shuffle some things around transparently.
I hope this will help you. Have a look at the config here.

JPA + Hibernate + java.util.logging (JDK logging): show sql queries with arguments

We are using JPA with Hibernate, and because we use the java build-in logging for our project, we have routed Hibernate to use java.util.logging (JDK logging) as well (by including slf4j-jdk14-1.6.4.jar). Now there is a problem with showing the actual queries that hibernate/JPA performs. We have added this to our persistence.xml:
<property name="hibernate.show_sql" value="true" />
That helps a bit, showing some more queries when inserting stuff. However, the question marks still remain. Other answers suggest to set the org.hibernate.type to TRACE in order to solve this, but that is a log4j specific suggestion. How can we actually show all arguments that hibernate uses? Thanks!
Alternative way is to use JDBC Driver Proxy logging library like log4jdbc
log4jdbc uses the Simple Logging Facade for Java (SLF4J) and supports below logging systems:-
Log4j
java.util logging in JDK 1.4
logback
Jakarta Commons Logging
It support showing SQL Queries with parameters ..here is an excerpt from their documentation
jdbc.sqlonly :- Logs only SQL. SQL executed within a prepared statement
is automatically shown with it's bind arguments replaced with the data
bound at that position, for greatly increased readability
create a logging.properties, add the line org.hibernate.SQL.level=FINEST, and launch your program with -Djava.util.logging.config.file=/path/to/logging.properties VM argument

eclipselink without persistence.xml and multiple persistence.xml

Hi I am trying to develop a JPA application using EclipseLink.
I am trying to create it without persistence.xml or at least the Persistence Unit will be created during run time. So I have an empty (or rather dummy) persistence.xml to start with.
I looked at this post eclipselink without persistence.xml but after debugging I noticed, EL forces to declare at least PU name and all other parameters can be set (including provider) during runtime.
Is there a way, PU can be created only during runtime? I am trying to create multiple PU based on number of categories in application which is known only during run time.
currently I am overwriting all other parameters except name (which I can't overwrite) and create a EM factory per category.
Thanks in advance,
Gopi
JPA defines a createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) in PersistenceProvider that does not require a persistence.xml (the container is responsible for processing it). You could probably call this directly on the EclipseLink PersistenceProvider, and pass your own PersistenceUnitInfo.
You may want to look into EclipseLink multitenancy support,
http://www.eclipse.org/eclipselink/documentation/2.4/solutions/multitenancy.htm#CHDBJCJA

How do I configure persistence.xml for ORM on glassfish v3 with Derby and Eclipselink

I'm using the internal glassfish 3.1 plugin for Eclipse, along with a derby database I installed (it shows up on the datasource explorer in the Database Developer view in Eclipse), and I'm fumbling at the "last" step of getting the ORM working so that I can develop an app that persists data with EJBs using Eclipselink for the JPA implementation.
I know I need to configure the persistence.xml file, but I'm at a loss for what needs to be in it, what the individual field names mean. I feel like the purpose of the persistence.xml is to tell Glassfish where to find the database to store everything in, and which JPA implementation to use to do that storing.
I have a bunch of questions.
Do I have to have a persistence entry for each class that represents an object in the database? So if I had a Book class and a Library class, would I need two enteries in persistence.xml or could I just do one case that services them both?
Where can I find more information about how to configure the persistence.xml file IN GENERAL. I have found tons of very specific tutorials with information on how to configure it in X, Y, or Z setting, but nothing that explains the individual bits, and how you'd configure them from a high level.
Once I've setup my persistence.xml file correctly, what else do I need to do to ensure that my #annotated classes are going to be serviced by the ORM implementation correctly? Is there something I need to configure in Glassfish?
I'm not an expert but...
1) Yes, in my experience you need an entry for each class. There could be exceptions to this but I am unfamiliar with them.
2) [http://wiki.eclipse.org/EclipseLink/] is a good place to start.
[http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA/persistence.xml] has some details that you may already know. I've have trouble finding a perfect resource myself. I've tended to find information fragmented all over the place.
3) In general most of my persistence.xml file has been generated automatically by eclipselink.
After I creating a connection pool and JDBC resource from the glassfish Administration Console
I had to add my
<jta-data-source>jdbc/your_name</jta-data-source>
to persistence.xml.[1]
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
I added these properties so my identity columns would auto-increment using JPA.
Try these two tutorials to get a better understanding of how it works:
[1] http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/#heading_toc_j_24
http://itsolutionsforall.com/index.php
[*apologies I can't post more than 2 links at the moment]