What is the difference between ddl-auto and hbm2ddl.auto? - spring-boot

Every time I try to start "Spring Boot Dashboard" from VSCode I get an error while using the following command.
spring.jpa.hibernate.ddl-auto=update (Doesn't Work)
However, I managed to find this line here on stack overflow that made it work. The problem is I don't know the difference and how will it impact my production.
spring.jpa.hibernate.hbm2ddl.auto=update (Works)
Any sort of help would be more than appreciated.

From this Link
spring.jpa.hibernate.ddl-auto This is actually a shortcut for the "hibernate.hbm2ddl.auto" property.
Defaults to "create-drop" when using an embedded database and no schema manager was detected. Otherwise, defaults to "none".
From this Stackoverflow Link
In production, it's often highly recommended you use none or simply don't specify this property. That is because it's common practice for DBAs to review migration scripts for database changes, particularly if your database is shared across multiple services and applications.

Related

Access sqlite db file with jpa

I have a huge sqlite file containing my db. I need to know if it is possible and how to connect to this db as an embedded one with jpa.
I'm developing an app that packs this database inside it's own jar so that when I use it on another system I don't have to import a copy of my db back and forth.
The technologies I'd like to use are Angular and Spring since those are the ones I know best. If there are some techonlogies that better suit this purpose I'd like some suggestions.
Thanks :)
I hope I undestood your question correctly, so I made a small project for you, hence you can have a look into it: spring-jpa-sqlite-sample. It may guide you a bit, though I and don't claim correctness or completeness.
The path to the sqlite file can easily be changed by inserting the correct url in the persistence.properties file:
driverClassName=org.sqlite.JDBC
url=jdbc:sqlite:src/main/resources/chinook.db --> you may use relative paths.
hibernate.dialect=dev.mutiny.semo.config.SQLiteDataTypesConfig
hibernate.hbm2ddl.auto=none
hibernate.show_sql=true
You can also use Environment variables from your system, which Spring tries to read from, so that you can reference the correct directory to a file. This can be found here: Read system environment var (SO)
Last but not least. Beware of using huge SQLite files. Find another way and transfer it first into a 'real' Database like any other Client/Server RDBMS you know (Oracle, MariaDB, MSSQL, depends on your scenario/taste).
Have closer look onto the documentation: When to use SQLite (and when not to!)

How to start Docker Axon server in development mode

I'm new to Axon and Docker and I would like to start axon server in Docker using developmnent mode in order to clear events as I'm in the process of building a system and my events and commands change often.
I read on Axon documentation that a certain property axoniq.axonserver.devmode.enabled (defaults to false) has to be set. I also know that Axon uses spring boot, so I guess I would need to somehow access the axonserver.properties on Docker, but here is the problem, i don't know how.
I would be thankful if anyone could explain how to change this configuration.
Fortunatelly Axon has been publishing blogs about running axon-server and one of them, they teach how to run it on docker =)
Blog post: https://axoniq.io/blog-overview/running-axon-server-in-docker
The important part, in your case, is here:
A third directory, not marked as a volume in the image, is important for our case: If you put an “axonserver.properties” file in “/config”, it can override the settings above and add new ones:
Which means, you can create your axonserver.properties in this directory with the desired property (axoniq.axonserver.devmode.enabled=true) and it will pick it up from there!
On the other hand, you can also set the environment variable: AXONIQ_AXONSERVER_DEVMODE_ENABLED to true.
Hope it helps.

Where to set Hibernate FlushMode?

I have an IntelliJ project using Spring MVC and with Hibernate FlushMode set to auto as default.
The problem is: when I try to delete an object from the db, using the web interface, it works fine, but after the third time I do that, the interface becomes not responsive (even though Hibernate receives the command to delete that certain object with that certain ID) and I have to reboot my WildFly server.
Any idea where I can change that? Is there a way to set it in a configuration file or I have to invoke a method to set it? And even if the problem is the FlushMode itself.
Regards
UPDATE: After testing several things, I think I finally found the root of the problem. If I access the db for more than three times consecutively, the server becomes unresponsive. How can I overcome this?
UPDATE#2: I found that the problem was that in the Dao the connection was opened but never closed (there wasn't a line "session.close()" just to be clear). And that was the reason After three pooling from the db, was it either to add items, delete them or just get infos, the server became unresponsive. Now everything works perfectly!
I actually didn't get your question properly.
The third time you try to delete something from your frontend, the web page gets stuck? The third time you make a delete request is the request stuck with hibernate? Could be a little clear about what actually is happening/or what issue you are facing.
To answer your question - how to setFlushMode in hibernate:
In case you using EntityManager -> entityManager.setFlushMode(FlushModeType.) -> JPA supports AUTO and COMMIT
In case you using SessionFactory:
sessionFactory.setHibernateFlushMode(FlushMode.) -> From hibernate 5
OR
sessionFactory.setFlushMode(FlushMode.) -> Before Hibernate 5
(NOTE: Please check the docs for accurate version of hibernate from which setFlushMode is deprecated.
Hibernate supports 4 modes of flush -> AUTO/COMMIT/ALWAYS/MANUAL

Is there a way to suppress SQL03006 error in VS2010 database project?

First of all, I know that the error I am getting can be resolved by creating reference project (of type Database Server) and then referencing it in my Database project...
However, I find this to be overkill, especially for small teams where there is no specific role separation between developers and db admins..But, let's leave this discussion for another time... Same goes for DACs...Can't use DAC b/c of limited objects supported...
Question
Now, the question is: Can I (and how), disable SQL03006 error when building my Database project. In my case this error is generated because I am creating some users whose logins are "unresolved"...I think this should be possible I hope, since I "know" that logins will exist on the server before I deploy the script...I also don't want to maintain database server project just so I can keep refs resolved (I have nothing besides logins at server level)...
Workaround
Using pre/post deployment scripts, it is trivial to get the secript working...
Workaround Issue
You have to comment out user scripts (which use login references) for workaround...
As soon as you do that, the .sqlpermissions bomb out, saying there is no referenced users...And then you have to comment permissions out and put them in post deploy scripts...
The main disadvantage of this workaround is that you cannot leverage schema compare to its fullest extent (you have to specify to ignore users/logins/permissions)
So again, all I want is
1. to maintain only DB project (no references to DB Server projects)
2. disable/suppress SQL03006 error
3. be able to use schema compare in my DB project
Am I asking for impossible? :)
Cheers
P.S.
If someone is aware of better VS2010 database project templates/tools (for SQL Server 2008 R2) please do share...
There are two workarounds:
1.
Turn off any schema checking (Tools > Options > Database Tools > Schema Compare > SQL Server 200x, then the Object Type tab) for anything user or security related. This is a permanent fix
2.
Go through the schema comparison and mark anything user or security related as Skip and then generate your SQL compare script. This is a per schema comparison fix.
It should be obvious but if you already have scripts in your project that reference logins or roles then delete them and they won't get created.

How to enable implicitCachingEnabled (statement caching) from Tomcat for oracle?

I've been reading about implicitCachingEnabled and MaxStatements with the oracle jdbc driver.
I've tried adding implicitCachingEnabled="true" into the server.xml for the datasource definition but it makes no difference.
I've also noted other posts admittedly from a long time ago, where people have failed to get this setting to work simply by setting it in the tomcat config files.
So just on the offchance someone has it working, is there a trick to it?
In the mean time i'll investigate whether it's possible or not to do this via code, but we're using JPA so i'm not sure how that'll work!
Thanks,
Dan
Try to set the value OracleConnection.setStatementCacheSize () instead of MaxStatements
http://www.stanford.edu/dept/itss/docs/oracle/10g/java.101/b10979/stmtcach.htm

Resources