Tag Archives: the table or view does not exist

Program error: the table or view does not exist [Solved]

When encountering this error, we mainly consider two aspects: one is the user’s permission, and the other is whether the table in the program corresponds to the table in the database, especially whether the table name is written correctly

I use the Oracle database connected by hibernate framework in the persistence layer

I asked the DBA to confirm that my current user does have read-write permission, especially for the table I reported an error; It shows that for other tables, there is no problem with insert, except for pri_ids_The mapping table is a dead or alive insert

The reason was later found:

@Entity
@Table(name = "Pri_Ids_mapping")
public class Pri_Ids_mapping {
    @Id
    @Column(name = "mapId", nullable = false)
    @SequenceGenerator(name = "seq_mapId", sequenceName = "SEQ_mapId",allocationSize= 1)
    @GeneratedValue(generator = "seq_mapId", strategy = GenerationType.SEQUENCE)
    private Long mapId;

}

 

There was a problem during the generation of the primary key of this table. Because the name of my sequence is not associated with the table name, it is particularly easy to be replaced by the sequence of other tables

In fact, there is a table sequence and seq in another library_Duplicate mapid name. Allow my users to use synonyms of this sequence when creating tables; In addition, when creating a sequence, users of the library in which it is located are allowed to use this synonym. In this way, later sequences will overwrite the original ones; Now I want to generate ID with sequence, which involves cross database, so there is a problem of insufficient access rights

Solution:

@Entity
@Table(name = "Pri_Ids_mapping")
public class Pri_Ids_mapping {
    @Id
    @Column(name = "mapId", nullable = false)
    @SequenceGenerator(name = "seq_mapId", sequenceName = "fhl_pms.SEQ_mapId",allocationSize= 1)
    @GeneratedValue(generator = "seq_mapId", strategy = GenerationType.SEQUENCE)
    private Long mapId;

}

 

When using sequences, just add the library name in front of them