2015-08-22 75 views
0

我有一個收集如下的Hibernate OGM映射到子集合

application 
* _id 
* name 
* desc 
* settings 
** _id 
** magento 
*** name 
*** keys 

我用下面的對象映射文檔

@Entity 
@Table(name = "applications") 
public class ApplicationEntity { 

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
@Type(type = "objectid") 
private String id; 

@Column(name = "applicationName") 
private String name; 

@Column(name = "desc") 
private String desc; 

@Embedded 
@Column(name = "settings.magento") 
private MagentoSettings magentoSettings; 

然而,對象「MangetoSettings」無法映射,它返回null。

我的問題是,我可以如何映射子文檔(magento),而無需在對象中聲明父(設置)?

假設「設置」文檔僅包含「Magento」,並且如果聲明具有單個屬性的「設置」對象將會浪費。

感謝

回答

0

我找到了答案在JBoss Hibernate的文檔here

您可以覆蓋用於嵌入對象的屬性列名。但是你需要知道默認的列名是嵌入屬性a的連接。 (點)和嵌入屬性(遞歸地嵌入對象的幾個級別)。

AttributeOverrides({ 
    @AttributeOverride(name="name", [email protected](name="settings.magento.name")), 
    @AttributeOverride(name="key", [email protected](name="settings.magento.key")) 
    }) 
private MagentoSettings magentoSettings; 

感謝