How to generate table definitions using JPA Tools with Eclipselink 2.5 - jpa

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

Related

Entity Framework Core configurations with existing database

In one of my projects, I am using an existing SQL Server database. All the database scripts are managed using DBUp and SQL script migrations.
In my application, I am using Entity Framework Core to communicate with this database. When I configure my entities in EF configurations, should I still define functions like IsRequired(), HasMaxLenth() etc.?
I am not using these EF configurations to generate migration scripts; all the migration is outside of EF. I am just using these configurations to communicate with the database.
When I configure my Entities in EF configurations, should I still define functions like IsRequired(), HasMaxLenth() etc.?
Other than table and column name mapping and data type mapping, it's not required, but additional model metadata might be used by front-end components for validation.
In general, yes, you should keep them. Many of these configurations are used throughout EF to make decisions at runtime. For example, some queries can be further optimized if EF knows that a column is never NULL, the max length is used to configure the SQL parameters it sends to the database, and unique constraints are used to sort SQL statements during SaveChanges.
While a few things like constraint names, non-unique indexes, index filters, and sequences aren't currently used at runtime, it's hard to know which ones EF will and won't use, so it's best just to keep them all.
And sometimes, database features like always encrypted on SQL Server, will fail entirely if the mappings aren't precise.

Eclipse JPA Tools generating duplicate fields in Generate Entities from Tables

JPA Tools -> Generate Entities from Tables... results in duplicate fields:
Predictably this results in this:
Not shown are all the duplicated getters and setters. Deleting them is a pain, even for a small class like this.
I cannot see any easy option to fix this. Does anyone have any ideas why it's happening? Thanks in advance.
This is true for mysql. I had three identical schemas with the same user table on mysql database instance. The entity created by the JPA Tools plugin had multiple fields with same name mapped to the multiple user tables in various schemas. Once I deleted all but one schema on the database, the tool retrieved correct list of fields that mapped to columns on the table
I had the same issue. I just renamed the other table in another schema. It seems that the Generate Entities from Table in Eclipse for a MySQL database looks for all tables with the same name no matter the schema.

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

Mysql Workbench Reverse Engineer function doesn't generate relationship "Lines" between tables

I just get a new project that need to work with a DB nobody knows about the structure about it. It is on the Mysql DB so I tried to use mySQL Workbench to export EER Diagram from this DB by using the Reverse Engineer function as many others recommended
I did get tables from the DB...but JUST tables!! no relationship that is the lines connect tables. Did I do something wrong or it is just because the ER Diagram from MySql Workbench is supposed to be like that?
Can anyone recommend tools that can export ER Diagram from existed DB? Include the relationship lines...
Relationships are only shown for foreign keys (how could MySQL Workbench otherwise know). If your tables have no foreign keys (e.g. because they are still using the MyIASM table engine instead of InnoDB) you won't get any relationships.

Sybase ASE 15.5 and which JPA implementation?

Which JPA implementation supports the following features against Sybase ASE 15.5 and how well?
Schema import (there is an existing server running; Hibernate does not even find existing tables.)
Schema export (maybe for new stuff; Hibernate seems to have no support for UNIVARCHAR)
stored procedure support
stored procedure import? (like schema import)
UNIVARCHAR type support (Hibernate does not per-se generate UNIVARCHAR columns, how about OpenJPA?)
TEXT type support.
schema migration including data migration tools
Any other pros/cons?
JPA is a runtime, not a development tool. Most of your questions seem to be tooling related, for which I would suggest using Eclipse JPA (Dali).
You can use any schema tools you want with any JPA provider, as long as they generate standard JPA metadata.
EclipseLink supports calling stored procedures on Sybase, including output parameters and multiple resultsets.
Any JPA provider should work at runtime with UNIVARCHAR and TEXT, to have the type used in default schema generation you would set them in the #Column columnDefinition, or customize the SybasePlatform in EclipseLink to use the type by default.