JPA em.find(id)在Oracle上有效,但在MariaDB上无效

时间:2018-11-22 11:53:40

标签: oracle hibernate jpa mariadb

您好,我有一个可以在JBoss EAP 7和JPA Hibernate上运行的应用程序。

我有一个简单的library(ggplot2) data = data.frame() for (x in seq(1,10)){ data = rbind(data, data.frame(x = rnorm(10, sd=0.1) + x, y = seq(10,1), group = x, category = c(rep("a", 3), rep("b", 3), rep("c", 3), "d"))) } data$group = as.factor(data$group) ggplot() + theme(legend.position="none", panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.title.y = element_blank(), axis.ticks.y=element_blank(), axis.text.y=element_blank()) + geom_path(data = data, mapping = aes(x=x, y=y, col= group, alpha=0.5)) + geom_point(data = data, mapping = aes(x=x, y=y, col= group)) 通话问题。

该调用针对Oracle 12数据库产生一个SQL

entityManager.find(id)

返回实体。

针对MariaDB,它会产生两个选择 休眠:

select messagedat0_.id as id1_4_0_,
       messagedat0_.messageid as messageid3_4_0_, 
       messagedat0_.messageblob as messageblob2_4_0_, 
       messagedat0_.messagetype as messagetype4_4_0_, 
       messagedat0_.retaintime as retaintime5_4_0_, 
       extractedv1_.messageid as messageid1_1_1_, 
       extractedv1_.absender as absender2_1_1_, 
       extractedv1_.empfaenger as empfaenger3_1_1_,
       extractedv1_.nachrichtentyp as nachrichtentyp4_1_1_, 
       extractedv1_.uuid as uuid5_1_1_ 
from messagedata messagedat0_
left outer join ExtractedValues extractedv1_ on messagedat0_.messageid=extractedv1_.messageid
where messagedat0_.id=?

当我手动运行两个选择时,第一个“选择”确实返回一行,第二个没有。 这将导致find方法返回NULL。我认为这不是预期的结果。

来自 消息数据实体:

select messagedat0_.id as id1_4_0_,
       messagedat0_.messageid as messagei3_4_0_,
       messagedat0_.messageblob as messageb2_4_0_,
       messagedat0_.messagetype as messaget4_4_0_,
       messagedat0_.retaintime as retainti5_4_0_,
       extractedv1_.messageid as messagei1_1_1_,
       extractedv1_.absender as absender2_1_1_,
       extractedv1_.empfaenger as empfaeng3_1_1_,
       extractedv1_.nachrichtentyp as nachrich4_1_1_,
       extractedv1_.uuid as uuid5_1_1_
from messagedata messagedat0_
left outer join ExtractedValues extractedv1_ on messagedat0_.messageid=extractedv1_.messageid
where messagedat0_.id=?

2018-11-22 09:46:36,328 INFO  [stdout] (default task-26) Hibernate:
select extractedv0_.messageid as messagei1_1_0_,
       extractedv0_.absender as absender2_1_0_,
       extractedv0_.empfaenger as empfaeng3_1_0_,
       extractedv0_.nachrichtentyp as nachrich4_1_0_,
       extractedv0_.uuid as uuid5_1_0_
from ExtractedValues extractedv0_ where extractedv0_.messageid=?

与ExtractedValues的OneToOne关系会导致MariaDB出现问题。 我尝试设置

@Id
private String id;

@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="messageid", referencedColumnName="messageid", updatable=false)
private Set<Msginformation> msginformations;

@OneToMany
@JoinColumn(name="messageid", referencedColumnName="messageid")
private Set<Protocol> protocols;

@OneToMany
@JoinColumn(name="messageid", referencedColumnName="messageid")
private Set<Retry> retries;

@OneToOne
@JoinColumn(name="messageid", referencedColumnName="messageid", insertable=false, updatable=false)
private ExtractedValues extractedValues;

在persistence.xml中,但这不能解决问题。 我不知道该怎么办...

3 个答案:

答案 0 :(得分:1)

我建议您使用以下两种方言之一:

org.hibernate.dialect.MariaDBDialect

org.hibernate.dialect.MariaDB53Dialect

答案 1 :(得分:0)

我希望您没有通过适当的方言。请检查方言。

您可以使用以下方言。

org.hibernate.dialect.MariaDBDialect

答案 2 :(得分:0)

感谢您的回答 我已经尝试过两种方言

       <property name="hibernate.dialect" value="org.hibernate.dialect.MariaDB53Dialect"/>

不幸的是,JBoss随后拒绝部署战争

无法将名称[org.hibernate.dialect.MariaDBDialect]解析为策略[org.hibernate.dialect.Dialect]

无法将名称[org.hibernate.dialect.MariaDB53Dialect]解析为策略[org.hibernate.dialect.Dialect]