内连接上的休眠选择错误

时间:2016-09-10 13:04:01

标签: java postgresql hibernate join

我使用hibernate / HQL

时遇到错误

我的表是table1(id,data),其中id - >主键和table2(id,anotherdata),其中id - >对table1.id的外键引用。

头等舱 - >

@Entity
@Table(name = "table1")
public class Table1 {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id;

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

    @OneToOne
    private Table2 table2;
    //construct, get, set
}

第二课 - >

@Entity
@Table(name = "table2")
public class Table2 {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private int id;

    @Column(name = "anotherdata")
    private String data;
    //get, set, construct
}

HQL查询 SELECT t1.id,t1.data,t2.data FROM Table1 as t1 JOIN t1.table2 as t2

休眠日志:从t1.t2_id = t2.id

中的table1 t1内连接table2中选择t1.id,t1.data,t2.anotherdata

此原因错误错误:列t1.t2__id不存在

在本声明的最后"在t1.t2_id = t2.id" 我应该在t1.id = t2.id&#上有" 34; (纯sql)

我该如何解决这个问题?将会感谢您的所有答案!

1 个答案:

答案 0 :(得分:0)

您的查询是正确的,但您应该更改映射:

Error:Error: Could not create the Java Virtual Machine.
Error:Error: A fatal exception has occurred. Program will exit.
Error:Error: Could not create the Java Virtual Machine.
Error:Error: A fatal exception has occurred. Program will exit.
Error:Invalid maximum heap size: -Xmx4g
Error:The specified size exceeds the maximum representable size.
Error:Invalid maximum heap size: -Xmx4g
Error:The specified size exceeds the maximum representable size.
:dmart-android:transformClassesWithDexForDev FAILED
Error:Execution failed for task ':dmart-android:transformClassesWithDexForDev'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_101\bin\java.exe'' finished with non-zero exit value 1