Is the revinfo table from Hibernate Envers obligatory? - hibernate-envers

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.

Related

Liquibase from JPA classes, no database yet

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..

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...

JPA changing entity table name on runtime

I have two tables with identical schema and data in MySql. one is using InnoDB engine and the other one using MyISAM engine.
I have mapped a JPA entity to InnoDB one and have trigger to update the MyISAM one,
but while querying records I want to use MyISAM version of the table with JPA queries but at the same time I cannot create entity for MyISAM one because it will increase maintenance and complexity.
I would create a #MappedSuperclass and have two subclasses for each table.
Otherwise, if you are using EclipseLink you could map to the table you wish to read from, and then override the insert, update and delete operations using a DescriptorCustomizer through the DescriptorQueryManager.

Unique indexes couldn't be exported to database by entity framework

I modeled a database with primary keys, foreign keys and unique indexes by using MySQL Workbench. I synchronized my model file with MySQL database and then created a console project in Visual Studio 2012. After that, i added a data entity model with an existing database. There is no problem. To understand if does entity framework create database successfully, i deleted the database. Then i ran the console program, database created successfully but unique indexes couldn't be exported to db. How can i solve this problem?
EF doesn't support unique keys. Unique keys are not used in the model and because of that it also doesn't create them when creating database from model. The only exception is manual creation of unique keys either through custom database intializer or migration (both are used in code-first approach).

How to deny EF update model from database for certain tables?

Is there a way to tell EF not to update SSDL for the single table when doing Update Model From Database?
A little more details:
We're using EF 4.3 with Db-first approach (so, edmx and Update Model From Database).
We have a table that for some reasons does not have a primary key set in SQL Server, but have an auto-incremented Identity column that we can tell EF to use as primary key.
Since EF isn't finding any primary key in a table itself, it generates a DefiningQuery in SSDL for that table (and prevent update/inserts).
I can easily delete that DefiningQuery (and modify other EntitySet attributes) and everything works fine.
Except when I do another Update Model From Database that DefiningQuery is back again.
Is there a way to tell EF not to update SSDL for that single table?
Is there a way to tell EF not to update SSDL for the single table when
doing Update Model From Database?
Not with default designer provided in Visual Studio. Once you modify SSDL part of your EDMX file you should maintain it manually or write a script which will fix it every time you run Update from database.
Alternatively you can buy more powerful designer or extension to Visual Studio which will offer you selective update.
Anyway what you are trying to do should be avoided. If the database is owned by ERP you should do the access only through ERP programming API (real ERP has some). Otherwise you can break functionality of your ERP, corrupt ERP data, cause performance issues or even cause deadlocks.