The type of the DBMS used is defined by the cuba.dbmsType and (optionally) cuba.dbmsVersion application properties and the configuration of javax.sql.DataSource
datasource, which the database access is made through. The instance of the datasource is extracted from the JNDI by name
specified in the cuba.dataSourceJndiName application property. The configuration file for Tomcat, which defines the datasource, is described in Section A.1, “context.xml”
The platform supports the following DBMS "out of the box":
cuba.dbmsType | cuba.dbmsVersion | |
---|---|---|
HSQLDB | hsql | |
PostgreSQL 8.4+ | postgres | |
Microsoft SQL Server 2005, 2008 | mssql | |
Microsoft SQL Server 2012+ | mssql | 2012 |
Oracle Database 11g | oracle |
The table below describes the recommended mapping of data types between entity attributes in Java and table columns in different DBMS. These types are automatically chosen by CUBA Studio when generating scripts to create and update the database. The operation of all platform mechanisms is guaranteed when using these types.
Java | HSQL | PostgreSQL | MS SQL Server | Oracle |
---|---|---|---|---|
UUID | varchar(36) | uuid | uniqueidentifier | varchar2(32) |
Date | timestamp | timestamp | datetime | timestamp |
java.sql.Date | timestamp | date | datetime | date |
java.sql.Time | timestamp | time | datetime | timestamp |
BigDecimal | decimal(p, s) | decimal(p, s) | decimal(p, s) | number(p, s) |
Double | double precision | double precision | double precision | float |
Long | bigint | bigint | bigint | number(19) |
Integer | integer | integer | integer | integer |
Boolean | boolean | boolean | tinyint | char(1) |
String (limited) | varchar(n) | varchar(n) | varchar(n) | varchar2(n) |
String (unlimited) | longvarchar | text | varchar(max) | clob |
byte[] | longvarbinary | bytea | image | blob |
As a rule, the whole work to convert the data between the database and the Java code is performed by the ORM layer in conjunction with the appropriate JDBC driver. This means that no manual conversion is required when working with the data using the EntityManager methods and JPQL queries you should simply use Java types listed in the left column of the table.
When using native SQL through EntityManager.createNativeQuery() or through QueryRunner some types in the Java code will be different from those mentioned above, depending on DBMS used. In particular, this applies
to attributes of the UUID
- type – only the PostgreSQL driver returns values of corresponding columns using this type; other servers return String
. To abstract application code from the DBMS used, it is recommended to convert parameter types and query results using the
DbTypeConverter interface.