- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 JPA 模型中有以下类(省略了 getter、setter 和不相关的字段):
@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@IdClass(PricePK.class)
public class Price {
@Id
@ManyToOne(optional = false)
private Product product;
@Id
@ManyToOne(optional = false)
private Currency currency;
}
@Embeddable
public class PricePK implements Serializable {
Integer product;
Integer currency;
}
@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Currency extends PersistentEntity {
@Id
private Integer ix;
}
@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Product extends AutoIdPersistentEntity {
}
@MappedSuperclass
public abstract class AutoIdPersistentEntity extends PersistentEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
}
我使用hbm2ddl hibernate3 Maven 插件的目标是从这些类生成 DDL。它为与 Price
类对应的表生成以下内容
create table PRICE (
currency_id int null,
product_id int null,
primary key (currency_id, product_id)
);
请注意,currency_id
和 product_id
都可以为 null,这会在我尝试将 DDL 加载到 SQL Server 时导致以下错误
Cannot define PRIMARY KEY constraint on nullable column in table 'PRICE'
我不明白为什么这些可以为空,因为在域模型中它们被注释了@ManyToOne(可选 = false)
DDL 是使用 org.hibernate.dialect.SQLServerDialect
SQL 方言生成的。
最佳答案
这有点令人困惑,但我认为可选属性(@ManyToOne、@Basic,...)不用于某些 JPA 实现的模式生成。
我认为你需要使用 @JoinColumn 注释并将 nullable 设置为 false: http://download.oracle.com/javaee/6/api/javax/persistence/JoinColumn.html
(或者在非连接情况下@Column:http://download.oracle.com/javaee/6/api/javax/persistence/Column.html)
关于java - 从 JPA 注释生成 DDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6444687/
有没有办法为模式差异生成 DDL,就像 TOAD 中的同步功能一样? 不确定如何使用“updateSQL”选项?我正在使用 diff 选项来比较模式。 最佳答案 您可以通过两个步骤来完成: 在两个模式
我正在向表中添加一些新列,并希望向表 DDL 添加文档以供将来的开发人员使用。如何解决这个问题? 最佳答案 通用语法: COMMENT ON {OBJECT} {OBJECTNAME} AS '{25
我有一个连接到 postgresql 数据库的 spring 项目。连接在此 application.yml 文件中定义: spring: datasource: #TODO replace ap
这个问题与Converting MySQL DDL to SQL Server DDL完全相反 . 我有一个 SQL Server 2008 DDL 文件。我想将其导入MySQL。 有什么工具或建议可
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找书籍、工具、软件库、教程或其他场外资源的问题对于 Stack Overflow 来说是
当下拉列表值已从某些外部资源修改时,如何在下拉列表的 JQuery 中调用更改事件? 如果我更改下拉列表中的值,下面的代码可以很好地工作。 Jan Feb $('#month').ch
我们有大量不同的数据源,包括 oracle、db2、mysql。我们还需要在最后添加一些审计列。我遇到了以下 Java 类 org.apache.sqoop.hive.HiveTypes。我计划创建一
我有一个为 MySQL 5 生成的模型,但现在我需要在 SQL Server 安装上创建这些表。 年以来我一直在使用 SQL 服务器,我想确保我可以将此脚本转换为兼容。 我真的不知道要寻找什么 TBQ
我的 View 中有三个 DDL。我在第一个 DDL 的“onchange”上触发一个 JavaScript 函数来填充第二个 DDL,并在第二个 DDL 的“onchange”上触发一个 JavaS
我试图将一个事件绑定(bind)到下拉列表,因为昨天没有任何帮助去 JavaScript 聊天室,没有人能够找到解决我的问题的方法,但后来我以某种方式尝试绑定(bind)我的下拉列表,如下所示 $('
我正在尝试学习如何为给定的 Hive 数据库中的所有表自动创建 DDL。 例如,我有一个名为 abc_db 的数据库。我写了一个Hive脚本,将所有的表写入一个名为abc_db.txt的文件中。文件中
我正在尝试使用jpa-ddl-maven-plugin,如here所述但我使用 Apache Maven 3.0.3 时收到以下错误。有什么想法我哪里出错了吗? 我的 pom.xml:
我是 Spring 和 Hibernate 的新手,我已经尝试了所有我能找到的方法来解决这个问题,但没有成功。任何帮助将不胜感激。我目前正在关注一本书中的一个示例项目,并且收到一条错误消息“Gener
鉴于架构: MACHINE_TYPE { machine_type } 机器{机器,机器类型} SORT_PLAN { sort_plan, machine_type } 日程表 { day_of_w
DML、DDL、DCL区别 . 总体解释: DML(data manipulation language): 它们是SELECT、UPDATE、IN
我需要在 Oracle 数据库上执行一堆(最多约 1000000 条)sql 语句。这些语句最后应该导致引用一致的状态,如果发生错误,所有语句都应该回滚。这些语句不是按引用顺序出现的。因此,如果启用了
在这种情况下,可能具有SQLITE DDL(LineNum为AUTO INCREMENT列是TransDate列的一部分)。如果我在行中插入新的每日交易条目,则将自动使用AUTO INCREMENT
我最近开始学习 hive 。我有一个具有以下值的python列表 list=['hello:struct', 'env:string', 'element:struct','AppId:string'
我正在将表从Hive 1迁移到HDInsight Hive 2,并且在从源到目标的表上重新创建表时,DDL中的以下行未正确解析: FIELDS TERMINATED BY ' ' COLLECTION
我正在尝试在 HSQL 数据库中重新创建一个 oracle 数据库。 这是为了在本地开发人员系统上进行更好的单元测试。 我需要知道的是,是否有任何我可以在 oracle 服务器/客户端中使用的工具/命
我是一名优秀的程序员,十分优秀!