我下面有2个实体Brand和BrandMerchantDefinition。在ACQ_BRAND表的brand_code列中,我有诸如00021,00022之类的数据(主要从零开始)。
in
它们在brand_code列上加入。
if pattern in file_contents:
print pattern
else:
print "No match!!"
我正在尝试找到具有@Entity
@Table(name = "ACQ_BRAND", schema = "ACQ")
public class BrandEntity {
@Id
@SequenceGenerator(name = "SEQ_ACQ_BRAND", sequenceName = "SEQ_ACQ_BRAND", allocationSize = 1)
@GeneratedValue(strategy = SEQUENCE, generator = "SEQ_ACQ_BRAND")
private Long id;
@Version
private Long version;
private String corporationCode;
private String brandCode;
private String brandDescription;
private String status;
@OneToMany(mappedBy = "brandCode", cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY)
private List<BrandMerchantDefinitionEntity> brandMerchantDefinitionEntities;
}
的实体。问题是,即使将brand_code列定义为@Entity
@Table(name = "ACQ_BRAND_MERCHANT_DEFINITION", schema = "ACQ")
public class BrandMerchantDefinitionEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_ACQ_BRAND_MERCHANT_DEFINITION")
@SequenceGenerator(sequenceName = "SEQ_ACQ_BRAND_MERCHANT_DEFINITION", name = "SEQ_ACQ_BRAND_MERCHANT_DEFINITION", allocationSize = 1)
private Long id;
@Version
@Column(name = "VERSION")
private Long version;
@Column(name = "STATUS")
private String status;
@ManyToOne(fetch = FetchType.EAGER, targetEntity = BrandEntity.class)
@JoinColumn(name = "BRAND_CODE", insertable = false, updatable = false, columnDefinition= "VARCHAR2(10)")
private BrandEntity brandCode;
@Column(name = "STORE_CODE")
private String storeCode;
@Column(name = "CITY_NAME")
private String cityName;
}
(和数据库中的brand_code = '00046'
),休眠也会将其提取为String
。
以下是生成的sql:
varchar2(10)
有趣的是,city_name是另一列包含数字的BIGINT
列。但是它开头不包含零,并且提取为 Hibernate:
/* dynamic native SQL query */ select
a.*
from
acq_brand_merchant_definition a,
acq_brand b
where
a.brand_code = b.brand_code
and a.brand_code =?
2018-12-04 18:39:15.940 TRACE 1640 --- [nio-8090-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [00046]
2018-12-04 18:39:16.140 TRACE 1640 --- [nio-8090-exec-1] o.h.type.descriptor.sql.BasicExtractor : extracted value ([id] : [BIGINT]) - [2]
2018-12-04 18:39:16.285 TRACE 1640 --- [nio-8090-exec-1] o.h.type.descriptor.sql.BasicExtractor : extracted value ([address] : [VARCHAR]) - [Adres]
2018-12-04 18:39:16.293 TRACE 1640 --- [nio-8090-exec-1] o.h.type.descriptor.sql.BasicExtractor : extracted value ([brand_code] : [BIGINT]) - [46]
2018-12-04 18:39:16.299 TRACE 1640 --- [nio-8090-exec-1] o.h.type.descriptor.sql.BasicExtractor : extracted value ([city_name] : [VARCHAR]) - [55]
。
如何强制Hibernate将VARCHAR2
的值提取为VARCHAR
?
答案 0 :(得分:0)
join列引用主键,即实体的id列。该名称指定为Long
,因此BIGINT
听起来是一个合理的选择。
如果要以String
/ VARCHAR
的身份进行处理,则需要将主键属性更改为String
。