[JAVA] Precautions when generating a table with a composite key with Iciql + SQLite

Introduction

When I made a table from a model with a combination of Iciql + SQLite, I had a hard time setting a composite primary key, so I will share information.

About Iciql

See here. http://iciql.com/

Version etc.

· Java version ... 8 ・ Version of iciql ... iciql-2.2.1 -Sqlite jdbc driver ... sqlite-jdbc-3.8.11.2.jar

Conclusion

Set the decryption key as follows. (Set the field name connected by commas in primaryKey)

@IQTable(name = "model", primaryKey= "field1,field2" )
public class Model {
	
	@IQColumn(name = "field1")
	public String field1;
	
	@IQColumn(name = "field2")
	public int field2;
	
	@IQColumn(name = "value")
	public String value;

}

Bad example 1

When I did this, the primary key was set only in field2. (Set the field name in primaryKey as an array)

@IQTable(name = "model", primaryKey={"field1","field2"} )
public class Model {
	
	@IQColumn(name = "field1")
	public String field1;
	
	@IQColumn(name = "field2")
	public int field2;
	
	@IQColumn(name = "value")
	public String value;

}

Bad example 2

Again, the primary key was set only in field2. (Set true for each primaryKey of @IQColumn)

@IQTable(name = "model")
public class Model {
	
	@IQColumn(name = "field1", primaryKey=true)
	public String field1;
	
	@IQColumn(name = "field2", primaryKey=true)
	public int field2;
	
	@IQColumn(name = "value")
	public String value;

}

About other DB

With postgres (*), both of the above bad examples 1 and 2 work as intended. We have not verified other DBs.

*) The version of postgres is 9.6, and the jdbc driver uses postgresql-9.4.1211.jar.

Recommended Posts

Precautions when generating a table with a composite key with Iciql + SQLite
FactoryBot, a solution when played with a foreign key validation
Precautions when writing a program: Part 3
Precautions when replacing backticks with gsub
Precautions when creating PostgreSQL with docker-compose
[Java] Precautions when comparing character strings with character strings