Tell Hibernate not to drop entities of library project - java

I have a library project called COMMON. COMMON is deployed to our company artifactory and is used by many other projects. In COMMON I have a few common entities. In one of the newer projects that does not yet have a database connection we see this error:
org.hibernate.tool.schema.internal.SchemaDropperImpl$DelayedDropActionImpl: HHH000478: Unsuccessful: drop table myschema.my_table if exists
This is frightening as these entities are not to be dropped. They are not even to be modified at line level as they are marked with #Immutable.
In the projects that use COMMON as a dependency I can tell hibernate not to do this with the following setting in application.properties:
spring.jpa.hibernate.ddl-auto=none
The problem with this is, that in project A if I want to use the ddl-auto feature on my A specific entities but not on the COMMON ones, I can't do that with this approach. Also if a dev forgets to add this property we drop the tables.
Can we restrict an Entity from being dropped/created in hibernate?

Related

How to prevent Hibernate Envers for creating Audit tables?

In my case, i have a dependency to a module that implementing envers in its domains (its domains were annotated with #Audited). When i imported that module in my pom.xml and run my app, envers automatically creating audit tables based on its domains. My question, how can i prevent Envers for creating audited tables after the domains were annotated with #Audited? Is there any solution like adding a configuration in application.properties file or something like that?
org.hibernate.envers.table_creation = false
If you're importing a dependency that uses Envers but you do not require the tables or its functionality in your environment, you can easily disable Envers via a simple hibernate setting
hibernate.integration.envers.enabled=false
This should prevent Envers from bootstrapping and building any envers schema and it should also prevent the event listeners from being registered when entity model events fire where we track changes and generate the audit entries.

Hibernate MySQL Find Unmapped Tables and Columns

I use Autogenerate DDL feature from Hibernate to create my tables and columns.
However, I end up deleting many columns in my entities but those columns remain in the database.
Is there a script that could identify those unmapped columns and tables so I could manually delete them?
Right now, I do it manually but it's becoming problematic as the database grows.
I am afraid you there is no automated way to do that.
Alternatively you can drop the whole table before building and loading the project and let hibernate re-create it with your defined column names.
The recommended thing is:
We should use the hibernate.hbm2ddl.auto property only in the development environment, not is the production
If hibernate.hbm2ddl.auto=create-drop, hibernate will drop and create a new database every time of deployment,
that means we can track the database state and its consistency.
If hibernate.hbm2ddl.auto=update, hibernate will only update the database with the changes to made in model/entity classes,
but it should not be trusted for the production environment/database.
hibernate.hbm2ddl.auto should be set to default for the production environment, so that no databases changes should be reflected from hibernate in production.

Hibernate HT_ Temporary Tables ON JOINED inheritance, Migration from Hibernate 3.4.0.GA To 5.1

I'm trying to migrate an application from Hibernate 3.4.0.GA to Hibernate 5.1, and after complete the required changes on java code, when I deploy the application I'm watching how Hibernate is trying to create HT_ tables (global temporary), one for each #Inheritance annotated entity.
Searching on Google I've found why the tables are being created.
But in my case we are not allow to change de database to add new tables.
My Inheritance model only has one level of Inheritance and its simple, example
Does anyone knows any alternative representation for a hierarchical table structure that I can use to avoid the HT_ tables creation, or some Hibernate configuration to archive the same purpose?.
I can change the inheritance hierarchy on our entities or the Hibernate configuration. I can also asume an exception on deploy caused by the non creation of the tables if it´s non blocking for the rest of the deploy.
Thank you in advance.
UPDATE 1: New info from Hibernate official forum.
UPDATE 2: The Bug was fixed
UPDATE 3: A blog entry explaining different bulk Strategies related to the issue
As in update one on this link is more info from Hibernate official forum with a possible solution.
UPDATE: Link with the solution
If you use Oracle Database with Spring and not sure where to define property for hibernate can do the following.
Add
spring.jpa.properties.hibernate.hql.bulk_id_strategy: org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy
In application.yml file from resource folder.

EclipseLink and H2

I trying to use EclipseLink JPA provider with H2 DBMS in Eclipse IDE.
When I create a new JPA project and fill the data (URL="jdbc:h2:~/test",Username="user",password="") connection type : resource local (I'm using the embedded mode)
I get 2 odd things :
when I try to create Entities from table I get a blank table list
I get an error message near #Entity notation saying that "catalog User can't be resolved for entity e1" or "Schema User can't be resolved for entity e1" depending on keeping the default value for catalog or changing it upon project creation where User is the database user name
The database already contains tables using the h2 console in Firefox
What is the cause of these problems and how can I solve it and do you have any page or book that can help with persistence.xml file (other than the oracle official web site)?
EclipseLink doesn't create the database tables for you, unless you explicitely tell it to do so.
The way to do that is described in the documentation
EclipseLink can be used to automatically generate the tables and database schema for a persistence unit. This is done through the "eclipselink.ddl-generation" persistence unit property, set to either "create-tables" or "drop-and-create-tables". The tables and constraints will be generated for all of the classes defined in that persistence unit.
The trick was to set the right catalog when creating the JPA Project and then every thing worked splendidly

Migrate to Hibernate Annotations from plain hibernate configuration - Also Database needs FK

Currently I have following scenario with my project :
Implemented Hibernate Configuration files (xml) mapping
Database doesn't have any FK relationship yet
So Now I wanna know that what are the things I need to keep in mind before migrating from hibernate xml configuration to hibernate annotations.
One more thing I wanna specify here is right now with my db i don't have any kind of FK relationship defined....
So obviously I will be applying FK first and then start migrating to annotations...
With this scenario Can anybody have any specific suggestion that I should follow ?
Thanks in advance...
Be very careful. Where I work we do everything with annotations so there shouldn't be any specific limitations as far as I can foretell.
It might be wise to migrate a logic chunk of your code at a time if at all possible. But basically it's just painstakingly running through your code and copying everything from the cofnig xml to your entity classes.

Categories

Resources