Liquibase from JPA classes, no database yet - jpa

We have started our application by our model classes, annotated with JPA annotations. We did not create any tables in the database yet.
Now, we would like to somehow generate a liquibase changelog by only looking at the JPA classes, maybe at file persistence.xml.
Most of the questions and answers about liquibase in SO suggest to run liquibase and compare it with the current state of the database. But that's not our case, because our database does not have any of the tables corresponding to the JPA entities, nor any of the liquibase control tables.
How do I generate a liquibase changelog file from the JPA entities?

you can take a look on liquibase-hibernate plugin https://github.com/liquibase/liquibase-hibernate/wiki
you can make a diff between your JPA entities against an empty database , and this will generate the whole changelog of the JPA entities..

Related

Is the revinfo table from Hibernate Envers obligatory?

Is this revinfo table obligatory for envers to even work properly? Or can I make a workaround using custom revision entities, without the need to even create revinfo in the database.
I'm asking because I'm developing a system using envers with spring and postgres database, but my superiors don't want a table to be created in the public schema.

Using JPA and JDBC together

In my project, we are upgrading an old J2EE application to Java EE 6.
Since the business logic is quite complex, we want to retain the EJB + DAO code as much as possible. The old code uses plain JDBC for database persistence.
But in our new/upgraded application, we plan to use JPA.
We would like to use JPA for all the read operations on database and use JDBC for the writes (inserts/updates/deletes). Is this possible in the same transaction?
For example:
obtain an Entity Manager reference and read an employee record from the database (employee entity) using entity manager find (or a named query)
convert the entity instance to a POJO
update the POJO
perform some business logic on the POJO (reuse old code as-is)
create a JDBC connection and use a prepared statement to update the employee record in database (reuse old code as-is)
Questions:
If I open 2 separate connections to the database - one from JPA and another from JDBC, will it still be in the same transaction (since app server manages the JTA transaction)?
What are the potential issues with this approach?
Since I am updating the database via JDBC, the entity in persistence context will not be in sync with the database. How to handle caching in such cases?
I looked at the following related threads, but I would like to know more in detail.
Combining JPA and JDBC actions in one transaction
Hibernate and JDBC in one transaction

How to generate table definitions using JPA Tools with Eclipselink 2.5

I tried to set-up tables in a MySql database with MySql Workbench including foreign keys, unique indexes, cascades on update/delete, ...
Then I let Eclipselink 2.5.1 create entities from tables with Project --> JPA Tools... in Eclipse. My hope was to see how I have to annotate classes, fields, methods to get the same result if I define the objects and run JPA Tools the other way around (Create Tables from Entities...).
Unfortunately I can't see anything of the previously defined cascading options or indexes in the created Java classes. Is there a way to make this way work?
For instance, I want to know how I can define the cascading option for update a I can do with #CascadeOnDelete (in MySql On Update stays 'RESTRICT')...or to find out why
#Table(name="geolocations",
uniqueConstraints=#UniqueConstraint(columnNames={"latitude", "longitude"}))
does not result in an index creation in the MySql table after running JPA Tools --> Create Tables form Entities...

Database Crawler using JPA

We have a requirement for building a database crawler. The application parses the tnsnames, connects to each database and retrieves some information like version, accounts, etc. We are trying to use JPA across the other parts of the application and to persist this data into the application's database.
So far, I only see creating an EntityManagerFactory programmatically for every database. Is there any other options?
We are using Spring, are there any benefits that Spring brings to the table in this scenario?
Thanks
JPA is clearly not the right tool for this job. JPA allows creating functional entities mapping a well-know database schema. Your tool doesn't know anything about the schemas and tables it will find. There could be 0 tables or 5000, with completely unknow names.
You need a much lower-level API to do what you want, like JDBC.
You could use JPA to store the results of your crawlings in a single schema, though.

Db schema is complete, can Entity Framework generate Storage Schema?

If I already have a database schema complete, can the entity framework somehow generate the storage schema for me?
Or if I have the classes developed, can it generate the other xml's desribing the classes and their relationships?
Most can yes... I believe what you would be looking for is hibernate tools (tools.hibernate.com). Toplink and other frameworks should have equivalent functionality. You essentially provide login/db provider information, and it queries the catalog and generates xml and classes