Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLOAT and DOUBLE commented out in Dialect #17

Open
chrber opened this issue Jul 1, 2020 · 4 comments
Open

FLOAT and DOUBLE commented out in Dialect #17

chrber opened this issue Jul 1, 2020 · 4 comments

Comments

@chrber
Copy link

chrber commented Jul 1, 2020

Hi,

first of all: Thank you for this dialect.

I use this one:

<dependency>
            <groupId>com.github.gwenn</groupId>
            <artifactId>sqlite-dialect</artifactId>
            <version>0.1.0</version>
</dependency>

And when I look at the code of the SQLiteDialect class, I see:

public SQLiteDialect() {
		registerColumnType( Types.BIT, "boolean" );
		//registerColumnType(Types.FLOAT, "float");
		//registerColumnType(Types.DOUBLE, "double");
		registerColumnType( Types.DECIMAL, "decimal" );
		registerColumnType( Types.CHAR, "char" );
		registerColumnType( Types.LONGVARCHAR, "longvarchar" );
		registerColumnType( Types.TIMESTAMP, "datetime" );
		registerColumnType( Types.BINARY, "blob" );
		registerColumnType( Types.VARBINARY, "blob" );
		registerColumnType( Types.LONGVARBINARY, "blob" );

Plus, the comment says that this dialect is appropriate for Hibernate 3


/**
 * An SQL dialect for SQLite 3.
 */
public class SQLiteDialect extends Dialect {
	private final UniqueDelegate uniqueDelegate;

Could you tell why this is the case?

Thank you very much.
Kind regards.
Christian

@gwenn
Copy link
Owner

gwenn commented Jul 2, 2020

Because, in the super constructor you can find:

		registerColumnType( Types.FLOAT, "float($p)" );
		registerColumnType( Types.DOUBLE, "double precision" );

And because, with SQLite:
https://sqlite.org/datatype3.html#affinity
Column types are used only for affinity.
As far as as know, SQLite supports only double precision.

But you should also have a look at:
https://hibernate.atlassian.net/browse/HHH-10668

SQLite type affinity and limited support for altering table means that hibernate.hbm2ddl.auto cannot be set to modify nor create (I seem to recall that FK constraints are added after tables).
And when hibernate.hbm2ddl.auto is set to validate, Hibernate don't know that 'float', 'double', 'real' means the same thing for SQLite.

So depending on your convention / the column type(s) you actually use, you may have to tweak this dialect.

@chrber
Copy link
Author

chrber commented Jul 3, 2020

Because, in the super constructor you can find:

		registerColumnType( Types.FLOAT, "float($p)" );
		registerColumnType( Types.DOUBLE, "double precision" );

And because, with SQLite:
https://sqlite.org/datatype3.html#affinity
Column types are used only for affinity.
As far as as know, SQLite supports only double precision.

But you should also have a look at:
https://hibernate.atlassian.net/browse/HHH-10668

SQLite type affinity and limited support for altering table means that hibernate.hbm2ddl.auto cannot be set to modify nor create (I seem to recall that FK constraints are added after tables).
And when hibernate.hbm2ddl.auto is set to validate, Hibernate don't know that 'float', 'double', 'real' means the same thing for SQLite.

So depending on your convention / the column type(s) you actually use, you may have to tweak this dialect.

The Reason I asked was, because I have a table that has some REAL columns. During the automatic creation of entities, I use Intellij Ultimate for that, these column types are converted to Object in Java. I think the dialect is used for this conversion, but I must confess, I have no idea about how this creation actually works. The thing that puzzled me was that REAL is transformed into Object even though SQlite documentation states that REAL, DOUBLE, DOUBLE PRECISION, FLOAT should be transformed into REAL (https://www.sqlite.org/datatype3.html#datatypes_in_sqlite). Could you enlighten me? Because this fact keeps me from enjoying auto creation of Java entities from my database. Thank you and kind regards. Christian

@gwenn
Copy link
Owner

gwenn commented Jul 3, 2020

As far as I know, you cannot generate Java entities from your database.
And the problem may be related to SQLiteDialect.
But also related to SQLite JDBC driver.
I am afraid you will have to investigate on your own.

@Cypher01
Copy link

I was also confused by these commented lines. But as I didn't experience any problems, I suggest to remove the two lines or even better replace them by comments that explain quickly something like "you don't find double and float here because they are in the super constructor".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants