创建下的SQLite在ORMLite外键约束 [英] Creating foreign key constraints in ORMLite under SQLite

查看:524
本文介绍了创建下的SQLite在ORMLite外键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于它是不能添加使用SQLite中的ALTER TABLE语句外键,我被困在如何配置我的数据库执行有效的外键,或执行级联删除没有明确的code开销。

任何人有一个想法如何SQLite的根据与ORMLite做到这一点?

解决方案
  

如何配置我的数据库执行有效的外键,或没有明确的code开销进行级联删除。

ORMLite支持 columnDefinition =... @DatabaseFiled 注释@Timo领域。我不知道,如果它提供你所需要的权力,但它确实让你有自定义栏定义。

  

<一个href="http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/field/DatabaseField.html#columnDefinition%28%29" rel="nofollow">http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/field/DatabaseField.html#columnDefinition()

如果没有的话,我怕你可能不得不在如此 ORMLite 以外创建数据库外壳。您可以使用 TableUtils.getCreateTableStatements()来获取必要创建表并添加您需要的执法和级联报表报表。下面是<一href="http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/table/TableUtils.html#getCreateTableStatements%28com.j256.ormlite.support.ConnectionSource,%20java.lang.Class%29"相对=nofollow> Javadoc中的方法。

As it is not possible to add foreign keys using an "ALTER TABLE" statement in SQLite, I am stuck on how to configure my database to enforce valid foreign keys, or perform cascaded deletes without explicit code overhead.

Anybody got an idea how to accomplish this with ORMLite under SQLite?

解决方案

how to configure my database to enforce valid foreign keys, or perform cascaded deletes without explicit code overhead.

ORMLite supports a columnDefinition="..." field in the @DatabaseFiled annotation @Timo. I'm not sure if it provides you the power you need but it does allow you to have custom column definitions.

http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/field/DatabaseField.html#columnDefinition()

If it doesn't then I'm afraid that you may have to create your database outside of ORMLite in this case. You can use TableUtils.getCreateTableStatements() to get the statements necessary to create the table and add the enforcement and cascade statements that you need. Here are the javadocs for that method.

这篇关于创建下的SQLite在ORMLite外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆