Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 左外连接不';t正确填充地图集合(HQL)_Hibernate_Join_Map_One To Many - Fatal编程技术网

Hibernate 左外连接不';t正确填充地图集合(HQL)

Hibernate 左外连接不';t正确填充地图集合(HQL),hibernate,join,map,one-to-many,Hibernate,Join,Map,One To Many,我有这样映射的类: @Entity public class CurrencyTable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; @Version @Column(nullable=false) private Timestamp version; @Column(length=32, unique=true) priv

我有这样映射的类:

@Entity
public class CurrencyTable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;

    @Version
    @Column(nullable=false)
    private Timestamp version;

    @Column(length=32, unique=true)
    private String refCode;

   @OneToMany(mappedBy="currencyTable", fetch=FetchType.LAZY, cascade =  {CascadeType.ALL})
   @MapKey(name="currency")
   private Map<String, CurrencyTableRate> rateMap = new HashMap<String, CurrencyTableRate>();
}

@Entity
public class CurrencyTableRate{
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;

    @Version
    @Column(nullable=false)
    private Timestamp version;

    @Column(length=3)
    private String currency;

    @Basic
    private BigDecimal rateValue;

    @ManyToOne(optional=false,fetch=FetchType.LAZY)
    private CurrencyTable currencyTable;
}
我在rateMap中得到一个包含三个条目的实体,但如果我尝试以下操作:

from CurrencyTable table left outer join fetch table.rateMap where refCode = :refCode
rateMap中只有一个条目

我查看了Hibernate生成的查询并手动运行它——正如预期的那样,它返回了三行,所以在获取之后映射它们似乎有问题。有人遇到过这样的问题吗?
我使用Hibernate版本3.2.6.ga和Oracle 10g

首先,我建议您在refCode中添加一个别名。我认为这不会对结果产生影响,只是以防万一

from CurrencyTable table left outer join fetch table.rateMap where table.refCode = :refCode
第二,打开您的SQL代码,分析SQL级别的实际情况。在这种情况下,我与HQL有类似的问题

from CurrencyTable table left outer join fetch table.rateMap map where map.id = :id
我得重写一下

from CurrencyTable table left outer join fetch table.rateMap map where EXISTS (SELECT a.id from CurrencyTable table a INNER JOIN a.rateMap m WHERE m.id = :id and table.id=a.id)

希望我的提示能有所帮助。

首先,我建议您在refCode中添加一个别名。我认为这不会对结果产生影响,只是以防万一

from CurrencyTable table left outer join fetch table.rateMap where table.refCode = :refCode
第二,打开您的SQL代码,分析SQL级别的实际情况。在这种情况下,我与HQL有类似的问题

from CurrencyTable table left outer join fetch table.rateMap map where map.id = :id
我得重写一下

from CurrencyTable table left outer join fetch table.rateMap map where EXISTS (SELECT a.id from CurrencyTable table a INNER JOIN a.rateMap m WHERE m.id = :id and table.id=a.id)

希望我的提示能有所帮助。

我添加了别名,但没有效果。正如我在问题中所写的那样,我查看了Hibernate生成的SQL查询并手动运行它——正如预期的那样,它返回了三行。我使用了一种变通方法,运行第一个查询(不带左外部连接获取),然后在映射上调用Hibernate.initialize。因为在我的工作中,我没有时间调试Hibernate以了解到底发生了什么,但这种行为让我感到不安:-)我添加了别名,但没有产生任何影响。正如我在问题中所写的那样,我查看了Hibernate生成的SQL查询并手动运行它——正如预期的那样,它返回了三行。我使用了一种变通方法,运行第一个查询(不带左外部连接获取),然后在映射上调用Hibernate.initialize。因为在我的工作中,我没有时间调试Hibernate以了解到底发生了什么,但这种行为让我心烦:-)我也有同样的问题,无法找到解决方案。我的查询有一段时间不起作用,抛出LazyInitializationException。我也有同样的问题,无法找到解决方案。我的查询有时不起作用,并引发lazyInitializationException