Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.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
Java 休眠@OneToOne和单个@Entity_Java_Hibernate_Mapping - Fatal编程技术网

Java 休眠@OneToOne和单个@Entity

Java 休眠@OneToOne和单个@Entity,java,hibernate,mapping,Java,Hibernate,Mapping,我目前正在将一些遗留代码移动到hibernate。在这个过程中,我参加了以下课程: public class Foo { private Bar b1; private Bar b2; private Bar b3; private Bar b4; private Bar b5; public Foo() { } public Foo(Bar b1, Bar b2, Bar b3, Bar b4, Bar b5) {

我目前正在将一些遗留代码移动到hibernate。在这个过程中,我参加了以下课程:

public class Foo {

    private Bar b1;
    private Bar b2;
    private Bar b3;
    private Bar b4;
    private Bar b5;

    public Foo() {

    }

    public Foo(Bar b1, Bar b2, Bar b3, Bar b4, Bar b5) {
        this.b1 = b1;
        this.b2 = b2;
        this.b3 = b3;
        this.b4 = b4;
        this.b5 = b5;       
    }
}
现在有趣的是,
Foo
不能映射到任何数据库表或视图,而
Bar
将映射到视图。现在很明显,我不能在这里使用任何注释,比如
@OneToOne
@JoinColumn
,因为它们依赖于现有的表/视图

所以我考虑使用HQL查询

select new com.fooCompany.test.Foo
(from Bar b1, from Bar b2, from Bar b3, from Bar b4, from Bar b5)
这也有点麻烦,不“好用”

所以我的问题是,有没有一种方法可以通过注释来解决它,或者这是目前处理此类类的唯一方法


如果您有任何问题,请随时提问