spring-projects/spring-ai · warning

Database product name is null or empty, defaulting to Postgr

Error message

Database product name is null or empty, defaulting to Postgres dialect.

What it means

In JdbcChatMemoryRepositoryDialect.from(), when the extracted database product name is null or empty, the dialect resolution logs this warning and defaults to PostgresChatMemoryRepositoryDialect. Your repository will then generate PostgreSQL-flavored SQL regardless of the actual database, which can break queries on other vendors.

Source

Thrown at memory-repositories/spring-ai-model-chat-memory-repository-jdbc/src/main/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepositoryDialect.java:76

	 */
	default String getDeleteMessagesSql() {
		return "DELETE FROM SPRING_AI_CHAT_MEMORY WHERE conversation_id = ?";
	}

	/**
	 * Detects the dialect from the DataSource.
	 */
	static JdbcChatMemoryRepositoryDialect from(DataSource dataSource) {
		String productName = null;
		try {
			productName = JdbcUtils.extractDatabaseMetaData(dataSource, DatabaseMetaData::getDatabaseProductName);
		}
		catch (Exception e) {
			logger.warn("Due to failure in establishing JDBC connection or parsing metadata, the JDBC database vendor "
					+ "could not be determined", e);
		}
		if (productName == null || productName.trim().isEmpty()) {
			logger.warn("Database product name is null or empty, defaulting to Postgres dialect.");
			return new PostgresChatMemoryRepositoryDialect();
		}
		return switch (productName) {
			case "PostgreSQL" -> new PostgresChatMemoryRepositoryDialect();
			case "MySQL", "MariaDB" -> new MysqlChatMemoryRepositoryDialect();
			case "Microsoft SQL Server" -> new SqlServerChatMemoryRepositoryDialect();
			case "HSQL Database Engine" -> new HsqldbChatMemoryRepositoryDialect();
			case "SQLite" -> new SqliteChatMemoryRepositoryDialect();
			case "H2" -> new H2ChatMemoryRepositoryDialect();
			case "Oracle" -> new OracleChatMemoryRepositoryDialect();
			default -> // Add more as needed
				new PostgresChatMemoryRepositoryDialect();
		};
	}

}

View on GitHub (pinned to 98a7beda4f)

Solutions

  1. Set the dialect explicitly on the builder so the Postgres default is never silently applied to a non-Postgres database
  2. Inspect why product name is empty: test dataSource.getConnection().getMetaData().getDatabaseProductName() directly
  3. If you use a proxy/wrapper DataSource, ensure it delegates getDatabaseProductName to the real connection
  4. Check whether your database's product name string is supported; if not, implement JdbcChatMemoryRepositoryDialect for it

Example fix

// before
JdbcChatMemoryRepository.builder().dataSource(unsupportedDbDataSource).build(); // defaults to Postgres

// after
JdbcChatMemoryRepository.builder()
    .dataSource(unsupportedDbDataSource)
    .dialect(new PostgresChatMemoryRepositoryDialect()) // explicit, intentional choice
    .build();
Defensive patterns

Strategy: validation

Validate before calling

try (Connection c = dataSource.getConnection()) {
    String productName = c.getMetaData().getDatabaseProductName();
    if (productName == null || productName.isBlank()) {
        logger.warn("Product name unavailable; configure dialect explicitly to avoid Postgres default");
    }
}

Prevention

When it happens

Trigger: from() called with a DataSource whose metadata returns a null/empty product name — connection issues swallowed earlier, drivers that do not implement the metadata call, or unusual/proxied datasources.

Common situations: Using a wrapper/proxy DataSource that doesn't delegate metadata; exotic or newer databases not in the known product-name list (PostgreSQL, MySQL/MariaDB, Microsoft SQL Server); misconfigured drivers; database down during startup with fallback continuing.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/4dad3a44358189cc. Report an issue: GitHub.