h2

How can I setup my environment to use h2 for tests and mysql for development?

旧时模样 提交于 2019-12-23 04:08:58
问题 I'm using the default configuration for the yo jhipster generator except that I'm using mysql as my "dev" database. When I run mvn test my tests succeed with no failures. However, I found that if I ran tests a second time, the suite would fail since it would run against the "dev" database...that wasn't 'rolled back' or 'reset' after the previous test run. I would rather have expected it to run against an in-memory h2 database as configured in src/test/resources/config/application.yml that

Efficiently query an embedded database in a loop with prepared statements

非 Y 不嫁゛ 提交于 2019-12-23 03:16:16
问题 I asked a similar question the other day but have since realized I was getting ahead of myself. I'm seeking advice on the proper way to handle the following scenario. I'm trying to SELECT the correct longitude and latitude for a given address and city, in the fastest way possible. My COORDINATES table has 25,000 rows and looks like this: I have a Java HashMap<Integer, List<String>> which contains an Integer as the key, and an ArrayList containing 2 entries, an address and city. The HashMap

How to set h2.jdbc from application.properties file?

拜拜、爱过 提交于 2019-12-23 03:13:20
问题 I am a fan of H2, and H2-Console. Unfortunatly, when i run the h2 on my java spring-boot application, by default the JDBC URL is as jdbc:h2:~/test meanwhile it should be jdbc:h2:mem:testdb to be able to see the saved objects. So, I am wondering if there is a way to configure this JDBC URL from the application.properties or not? The below image shows better what i am talking about: 回答1: You can use below properties for connecting h2 database via application.properties file spring.h2.console

H2 cluster weird behavior : fake referential Integrity violation on foreign key

懵懂的女人 提交于 2019-12-23 02:25:59
问题 I run H2 in cluster mode with 2 nodes. I have two tables. A parent, and a child. The child contains a foreign key to the ID of a row of the parent table. I'm experiencing a weird issue that I can not understand : everything is working OK until I violate a unique constraint. Steps: - Everything is working normally - I violate (by purpose here) a Unique constraint - Now when adding child rows, I get a referential integrity violation on the foreign key (parent.id), but the child row is properly

H2 db not accessible at localhost:8080/h2-console when using webflux

我是研究僧i 提交于 2019-12-22 18:25:09
问题 H2 db is not accessible at localhost:8080/h2-console when using webflux. I read somewhere that this is available only when developing a Servlet based application. But I am using Webflux with Netty. So is there a way to see the h2 console in such an application? 回答1: I had the same issue, I ended up booting the console server manually on another port: @Component @Profile("test") // <-- up to you public class H2 { private org.h2.tools.Server webServer; private org.h2.tools.Server server;

Hibernate H2 database relative path

穿精又带淫゛_ 提交于 2019-12-22 13:48:09
问题 I have an H2 database file calls "test.db". The file is located in my application directory: "myApp/resources/test.db". I'm not able to get this works for me.So, what's the correct way to refere to a relative path. Here is the configuration of my hibernate.cfg.xml. <property name="connection.driver_class">org.h2.Driver</property> <property name="connection.url">jdbc:h2:file:/test</property> <property name="connection.username">test</property> <property name="connection.password">1234<

transactions not working with Spring 3.1 – H2 – junit 4– hibernate 3.2

こ雲淡風輕ζ 提交于 2019-12-22 10:45:04
问题 I have the following test.. @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/schedule-agents-config-context.xml"}) @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true) @Transactional public class H2TransactionNotWorkingTest extends SubmitAgentIntegratedTestBase { private static final int FIVE_SUBMISSIONS = 5; @Autowired private ApplicationSubmissionInfoDao submissionDao; private FakeApplicationSubmissionInfoRepository

Create alias which works for strings and numbers in H2

◇◆丶佛笑我妖孽 提交于 2019-12-22 10:06:14
问题 I want to create an alias for the IF function in H2 for MySQL compatibility as asked here. Vituels answer explains how to do this with CREATE ALIAS: CREATE ALIAS IF NOT EXISTS `IF` AS $$ String ifFunction(boolean condition, String exp1, String exp2){ if(condition) { return exp1; } else { return exp2; } } $$; This works if you use the alias with string parameters, but does not work for numbers. If I use Integer in the alias definition instead of String , it's the other way round. Using Object

Query Failing in Postgres but Working in H2 (Postgres Mode)

旧时模样 提交于 2019-12-22 09:20:03
问题 I often find myself in a situation where I want to write automated tests for my database queries. My current use case is a Spring MVC web app and a Postgres database. As far as I can tell, I have two options: Stand up an actual Postgres instance and initialize it with a test data set Utilize an in-memory database such as H2. I have used Option #1 in the past (albeit with an Oracle database and Oracle XE) with good success. The main downfall of this approach is that the tests aren't self

Adding the NOT_NULL constraint to an SQL column

时光毁灭记忆、已成空白 提交于 2019-12-22 07:05:19
问题 I'm trying to add the NOT_NULL constraint to a column in an SQL h2 database, using ALTER TABLE CHARACTERS ADD CONSTRAINT nn_PID NOT_NULL (PLAYER_ID); This follows the pattern I found here: ALTER TABLE Persons ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName) Except I change the constraint, table and column names. But I get this error: Syntax error in SQL statement "ALTER TABLE CHARACTERS ADD CONSTRAINT NN_PID NOT_NULL[*] (PLAYER_ID) "; expected "., COMMENT, PRIMARY, INDEX, KEY, CHECK,