Hibernate查找表/类型的注释? [英] Annotations for Hibernate lookup table/type?
问题描述
我试图将Hibernate与 hbm2ddl.auto
设置为 validate
,以便Hibernate必须尊重我的数据库模式,而不是围绕我的Java类自动生成表。
我的很多表是所谓的lookup或reference表,它们基本上由 id
, name
和 tag
字段:
credit_card_types
credit_card_type_id例如:12
credit_card_type_name例如:Visa
credit_card_type_tag例如:VISA
payment_types
payment_type_id例如:2
payment_type_name例如:Google Checkout
payment_type_tag EX:GOOGLE_CHECKOUT
等
我想对这些模型进行建模,如下所示:
public class BaseLookup {
private Long id;
私人字符串名称;
私人字符串标签;
// ... getters,setters和ctors等
}
公共类CreditCardTypes扩展BaseLookup {
// ..也许是a其他几个领域,方法等...
}
公共类PaymentTypes扩展BaseLookup {
// ..也许还有其他一些字段,方法等...
}
问题是我不希望Hibernate搜索(验证) 我需要哪些注释/配置来允许这种类型的Java继承,但仅创建我的2个查找表(而不是3)?提前致谢! 对于您的基类,您将添加以下注释: 对于您的子类,您可以执行以下操作: 你可以用同样的方式完成第二课: I am trying to use Hibernate with A lot of my tables are so-called "lookup" or "reference" tables, that essentially consist of I'd like to model these as follows: The problem is I don't want Hibernate to search for (validate against) a What annotations/configs do I need to allow this type of Java inheritance but to only create my 2 lookup tables (and not 3)? Thanks in advance! For your base class you would add the following annotation: And for your children classes you would do the following: And you could do the second class in the same manner:
这篇关于Hibernate查找表/类型的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! lookups
table:我希望它能够验证名为 credit_card_types
和 payment_types 的aginst 2查找表。 code>分别。
@MappedSuperclass
public class BaseLookup实现Serializable {
@Id
@Col umn(name =ID)
私人长ID;
@Column(name =NAME)
私人字符串名称;
@Column
私人字符串标签;
// ... getters,setters和ctors等
}
@Table(name =CREDITCARDTYPES)
public class CreditCardTypes扩展BaseLookup {
// ..也许还有其他一些字段,方法等...
@Coulmn(name =FIELD1_COLUMN_NAME)
私人字符串field1;
}
@Table(name =PAYMENTTYPES)
public class PaymentTypes extends BaseLookup {
// ..也许一些其他字段,方法等...
@Coulmn(name =FIELD2_COLUMN_NAME)
private String field2;
}
hbm2ddl.auto
set to validate
so that Hibernate must respect my DB schema, instead of auto-generating tables around my Java classes.id
, name
and tag
fields:credit_card_types
credit_card_type_id Ex: "12"
credit_card_type_name Ex: "Visa"
credit_card_type_tag Ex: "VISA"
payment_types
payment_type_id Ex: "2"
payment_type_name Ex: "Google Checkout"
payment_type_tag EX: "GOOGLE_CHECKOUT"
etc.
public class BaseLookup {
private Long id;
private String name;
private String tag;
// ...getters, setters and ctors, etc.
}
public class CreditCardTypes extends BaseLookup {
// .. perhaps a few other fields, methods, etc...
}
public class PaymentTypes extends BaseLookup {
// .. perhaps a few other fields, methods, etc...
}
lookups
table: I want it to validate aginst 2 lookup tables called credit_card_types
and payment_types
respectively.@MappedSuperclass
public class BaseLookup implements Serializable {
@Id
@Column (name="ID")
private Long id;
@Column (name="NAME")
private String name;
@Column
private String tag;
// ...getters, setters and ctors, etc.
}
@Table(name = "CREDITCARDTYPES")
public class CreditCardTypes extends BaseLookup {
// .. perhaps a few other fields, methods, etc...
@Coulmn (name="FIELD1_COLUMN_NAME")
private String field1;
}
@Table(name = "PAYMENTTYPES")
public class PaymentTypes extends BaseLookup {
// .. perhaps a few other fields, methods, etc...
@Coulmn (name="FIELD2_COLUMN_NAME")
private String field2;
}