简体   繁体   中英

JPA 2.0 / EclipseLink and sqlite 3.7.2 - Can't create the tables

I'd like to use JPA 2.0 with EclipseLink (2.4.0) and sqlite 3.7.2 in a simple Java Swing application.

The first thing I have encountered is, that EclipseLink doesn't support sqlite. Here is the output:

[EL Info]: 2012-09-18 18:05:42.246--ServerSession(31125695)--EclipseLink, version: Eclipse Persistence Services - 2.4.0.v20120608-r11652

[EL Info]: connection: 2012-09-18 18:05:42.352--Not able to detect platform for vendor name [SQLite3]. Defaulting to [org.eclipse.persistence.platform.database.DatabasePlatform]. The database dialect used may not match with the database you are using. Please explicitly provide a platform using property eclipselink.platform.class.name.

However, it seems to me, that the configuration works almost fine.

But when I have a model with related Entities (ie @ManyToOne) the tables can't be created automatically.

[EL Warning]: 2012-09-18 18:05:42.629--ServerSession(31125695)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near "CONSTRAINT": syntax error) Error Code: 0

Call: ALTER TABLE blub ADD CONSTRAINT FK_blub_customer_id FOREIGN KEY (customer_id) REFERENCES customer (customer_id)

Query: DataModifyQuery(sql="ALTER TABLE blub ADD CONSTRAINT FK_blub_customer_id FOREIGN KEY (customer_id) REFERENCES customer (customer_id)")

As you can see, the additional creation of foreign key constraints isn't supported by sqlite.

Do you have any idea how to fix the problem?

Best regards

Add your own DatabasePlatform subclass and add the method,

public boolean supportsForeignKeyConstraints() {
        return false;
}

Then use this platform using the "eclipselink.target-database" property.

Please also log a bug to have SQLite support added, and attach your platform if you are successful creating one.

UPDATE 18/08/2015
Not sure if this option is new, you can now set foreign_keys to false in the JDBC connection configuration/properties. In such way you will avoid these warning messages and it will create the foreign keys as needed. One way to set it is using:

SQLiteConfig config = new SQLiteConfig();
config.enforceForeignKeys(false);
Properties dbProps = config.toProperties();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM