0

I have the following two tables in my database:

CREATE TABLE ACCOUNT (
    ID NUMBER(19, 0) NOT NULL,
    AA_ID VARCHAR2(11 CHAR),
    BB_ID VARCHAR2(8 CHAR),
    STATUS NUMBER(1, 0) DEFAULT 1,
    CREATED_AT TIMESTAMP(6) NOT NULL,
    LAST_MODIFIED_AT TIMESTAMP(6)
) TABLESPACE $tbsp;

CREATE TABLE MOBILE_INSTANCE (
    ID NUMBER(19, 0) NOT NULL,
    ACCOUNT_ID NUMBER(19, 0) NOT NULL,
    APPLICATION_ID VARCHAR2(36 CHAR) NOT NULL,
    TOKEN VARCHAR2(255 CHAR) NOT NULL,
    DEVICE VARCHAR2(13 CHAR),
    STATUS VARCHAR2(10 CHAR),
    CREATED_AT TIMESTAMP(6) NOT NULL,
    LAST_MODIFIED_AT TIMESTAMP(6)
) TABLESPACE $tbsp;

And the connection between them:

ALTER TABLE MOBILEBANK_INSTANCE ADD CONSTRAINT FK_MOBILEBANKINSTANCE_ACCOUNT FOREIGN KEY (ACCOUNT_ID) REFERENCES ACCOUNT(ID);

So far, this is working like a charm...

Via JPA, I have created the entites for these tables - please see the following snippet of my entities:

In the MobileInstance entity I have marked the @ManyToOne connection as following:

@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ACCOUNT_ID")
    private Account accountId;

And this is how it looks like in my Account entity class:

@OneToMany(mappedBy = "accountId", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<MobileInstance> mobileInstanceList = new ArrayList<>();

As you see, the accountId field (which is in the Account table actually a Long value) is marked as an Account object.

Later on, when I have already an account object, I whish the create a mobileInstance object as well, with the appropiate account ID.

But when I call:

mobileInstance.setAccountId

it requieres an account parameter... When I assigne one to it and try to save it in the DB, I got the error:

ERROR SqlExceptionHelper:131 - ORA-00904: "APPLICATION_ID": invalid identifier

I assume, it is because the Application ID field in the Database is a Number field, and I assigne to it a whole Account object which I do not want to change to Long..

Is there a way the code to recognize that only use the primary key of my Account table?

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
dorcsi
  • 295
  • 2
  • 6
  • 24

0 Answers0