2017-07-19 58 views
0

我有这样的:插入休眠NamedQuery与嵌入式领域

public class A { 

    private B b; 

    @Embedded 
    public B getB() { 
     return b; 
    } 

    public void setB(B b) { 
     this.b = b; 
    } 
} 

@Embeddable 
public class B { 

    private String b1; 
    private String b2; 

    //constructor 
    //accessors 
} 

@NamedQuery(name = "create", query = "insert into A(b1) values ('test')") 

但我得到这个错误:

org.hibernate.QueryException: could not resolve property: b1 of: com.blabla.A 

我不知道该怎么称呼我的嵌入式类的属性和我不在互联网上找到任何例子。是否有人知道我可以如何调用b1属性?

谢谢。

+0

A类还没有属性B1。其属性称为b。 –

+0

是的,但是因为B被嵌入了,我应该能够访问b1对吗? 我试图插入A(B.b1)的值...太 –

回答

0

尝试丝毫这样的:

public class A { 
@Embedded 
@AttributeOverrides(value={ 
    @AttributeOverride(name = "b1", @Column()), 
    @AttributeOverride(name = "b2", @Column()) 
}) 
private B b; 


public B getB() { 
    return b; 
} 

public void setB(B b) { 
    this.b = b; 
}} 

而且你必须NamedQuery工作:@NamedQuery(name = "create", query = "insert into A(b1) values ('test')")