JPA中使用复合键进行一对一映射

时间:2014-04-29 11:14:34

标签: java hibernate jpa

我在hibernate中使用JPA 2注释并尝试在表中插入行" TABLEB"但得到了以下错误。

@Embeddable   
public class TableAId implements Serializable{

    @Column(name="ID")
    private int id;

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


   //hashcode and equals

   //getters and setters

}


@Entity
@Table(name = "TABLEA")
public class TableA implements Serializable{

    @EmbeddedId
    private TableAId tableAid;

    @Lob
    @Type(type="text")
    @Column(name="STR",length = Integer.MAX_VALUE)
    private String str;

    @Version 
    @Column(name="VERSION")
    private int version;


    //getters and setters


 }

    @Entity
    @Table(name = "TABLEB")
    public class tableB implements Serializable{
    @Id
    @Column(name="TABLEBNAME")
    private String tableBName;

    @OneToOne
    private TableA tableA;


    //getters and setters


 }

数据库表

CREATE TABLE TABLEA(ID NUMBER(10,0) , NAME VARCHAR2(4000 BYTE),STR CLOB,CONSTRAINT PK_TABLEA PRIMARY KEY (ID,NAME));


REATE TABLE TABLEB(TABLEBNAME VARCHAR2(3209 BYTE) NOT NULL PRIMARY KEY,NAME VARCHAR2(4000 BYTE), ID NUMBER(10,0) ,CONSTRAINT FK_TABLEA FOREIGN KEY(ID,NAME)REFERENCES    TABLEA(ID,NAME));

错误消息

Hibernate: insert into TABLEB (TABLEA_ID, TABLEA_NAME, TABLEBNAME) values (?, ?, ?)

Apr 29, 2014 4:27:23 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions

WARN: SQL Error: 904, SQLState: 42000

Apr 29, 2014 4:27:23 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00904: "TABLEA_NAME": invalid identifier

任何人都可以为上述场景提出任何解决方案(使用复合键进行一对一映射)。 任何帮助,将不胜感激。 提前谢谢。

0 个答案:

没有答案