How to integrate SQLite with Spring Boot having Hiberate 6

I’m trying to integrate SQLite.
For that before hibernate 6 we were able to do it by using class extending Dialect
but from hibernate 6 onwards registerColumnType and registerFunction methods, StandardSQLFuntion(String, Type registeredType) are not available anymore how can I overcome this issue in hibernate 6?

registerColumnType(Types.BIT, "integer");
   	registerColumnType(Types.TINYINT, "tinyint");
   	registerColumnType(Types.SMALLINT, "smallint");
   	registerColumnType(Types.INTEGER, "integer");
   	registerColumnType(Types.BIGINT, "bigint");
   	registerColumnType(Types.FLOAT, "float");
   	registerColumnType(Types.REAL, "real");
   	registerColumnType(Types.DOUBLE, "double");
   	registerColumnType(Types.NUMERIC, "numeric");
   	registerColumnType(Types.DECIMAL, "decimal");
   	registerColumnType(Types.CHAR, "char");
   	registerColumnType(Types.VARCHAR, "varchar");
   	registerColumnType(Types.LONGVARCHAR, "longvarchar");
   	registerColumnType(Types.DATE, "date");
   	registerColumnType(Types.TIME, "time");
   	registerColumnType(Types.TIMESTAMP, "timestamp");
   	registerColumnType(Types.BINARY, "blob");
   	registerColumnType(Types.VARBINARY, "blob");
   	registerColumnType(Types.LONGVARBINARY, "blob");
   	// registerColumnType(Types.NULL, "null");
   	registerColumnType(Types.BLOB, "blob");
   	registerColumnType(Types.CLOB, "clob");
   	registerColumnType(Types.BOOLEAN, "integer");

   	registerFunction("concat", new VarArgsSQLFunction(StringType.INSTANCE, "", "||", ""));
   	registerFunction("mod", new SQLFunctionTemplate(StringType.INSTANCE, "?1 % ?2"));
   	registerFunction("substr", new StandardSQLFunction("substr", StringType.INSTANCE));
   	registerFunction("substring", new StandardSQLFunction("substr", StringType.INSTANCE));

The hibernate-community-dialects module comes with a SQLite dialect: hibernate-orm/SQLiteDialect.java at main · hibernate/hibernate-orm · GitHub

Use that one

1 Like

Thank you for solution :100:

Can you post the actual solution? Using the driver still fails to connect for me. I was able to connect to MySQL, H2, and Postgres, but SQLite is failing.

driver = “com.mysql.cj.jdbc.Driver”;
dialect = "org.hibernate.community.dialect.SQLiteDialect ";

You are trying to use the MySQL driver to connect to a SQLite database? Maybe you should think about what you wrote here or at least re-read it before clicking reply :wink:

still i got this error SQLiteIdentityColumnSupport cannot be resolved to a variable

I am still facing the same error. I went through this discussion and it seems that currently, it’s not supporting at all.

java.lang.NoClassDefFoundError: org/hibernate/dialect/unique/AlterTableUniqueDelegate
	at org.hibernate.community.dialect.SQLiteDialect.<init>(SQLiteDialect.java:110)
	at org.hibernate.community.dialect.SQLiteDialect.<init>(SQLiteDialect.java:105)
	at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
	at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
	at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:304)
	at java.base/java.lang.Class.newInstance(Class.java:725)
	at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.lambda$constructDialect$0(DialectFactoryImpl.java:112)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:241)
	at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:190)
	at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:96)
	at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:59)
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:244)
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:36)
	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:119)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:255)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:230)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207)
	at org.hibernate.boot.model.relational.Database.<init>(Database.java:44)
	at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getDatabase(InFlightMetadataCollectorImpl.java:218)
	at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:191)
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:138)
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:97)
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:402)
	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:90)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:735)
	at io.dropwizard.hibernate.SessionFactoryFactory.buildSessionFactory(SessionFactoryFactory.java:103)
	at io.dropwizard.hibernate.SessionFactoryFactory.build(SessionFactoryFactory.java:52)
	at io.dropwizard.hibernate.SessionFactoryFactory.build(SessionFactoryFactory.java:42)
	at io.dropwizard.hibernate.HibernateBundle.run(HibernateBundle.java:73)
	at io.dropwizard.core.setup.Bootstrap.run(Bootstrap.java:199)
	at io.dropwizard.core.cli.EnvironmentCommand.run(EnvironmentCommand.java:65)
	at io.dropwizard.core.cli.ConfiguredCommand.run(ConfiguredCommand.java:98)
	at io.dropwizard.core.cli.Cli.run(Cli.java:78)
	at io.dropwizard.core.Application.run(Application.java:94)
	at com.prepsmith.PrepSmithApplication.main(PrepSmithApplication.java:21)
Caused by: java.lang.ClassNotFoundException: org.hibernate.dialect.unique.AlterTableUniqueDelegate
	... 36 more

The version of hibernate-core and hibernate-community-dialects obviously have to match. The error suggests you are using different versions.