Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate fails to create foreign key in Oracle between different schemas
    primarykey
    data
    text
    <p>I have a java7+Spring3.2.0+hibernate3 application that used a <code>Postgresql</code> database. Now I have to migrate this application to use the latest Oracle.</p> <p>When at startup I set hbm2ddl to "create" the tables are created correctly, but all the foreign keys that involve tables located in different schemas fails with the error: <code>ORA-00942: table or view does not exist</code></p> <p>The database is quite big and involve many different schemas. I can't change the structure of the database. Here is an example of the mapping:</p> <pre><code>@Entity @Table(name="brands", schema="live", uniqueConstraints=@UniqueConstraint(columnNames={"name"})) public class Brand implements Serializable { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="brands_seq_gen") @SequenceGenerator(name="brands_seq_gen", sequenceName="brands_seq",schema="live",allocationSize=1) @Column(name = "id") private Integer id; ... } @Entity @Table(name="campaign_group", schema="campaign") public class CampaignGroup implements Serializable { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="campaign_group_seq_gen") @SequenceGenerator(name="campaign_group_seq_gen", sequenceName="campaign_group_seq",schema="campaign",allocationSize=1) @Column(name = "id") protected Long id; @ManyToOne(fetch = FetchType.LAZY, cascade={CascadeType.MERGE}) @JoinColumn(name="brand_id") protected Brand brand; </code></pre> <p>At start up the tables are created correctly and they are in the database but then I get this error:</p> <pre><code>DEBUG org.hibernate.tool.hbm2ddl.SchemaExport [] - alter table campaign.campaign_group add constraint FKB1854E905348D509 foreign key (brand_id) references live.brands ERROR org.hibernate.tool.hbm2ddl.SchemaExport [] - Unsuccessful: alter table campaign.campaign_group add constraint FKB1854E905348D509 foreign key (brand_id) references live.brands ERROR org.hibernate.tool.hbm2ddl.SchemaExport [] - ORA-00942: table or view does not exist </code></pre> <p>I've created all users/schema with the <code>SQL: CREATE USER</code> campaign <code>IDENTIFIED</code> BY <code>dsa123 QUOTA UNLIMITED</code> ON system;</p> <p>I'm using the SYSTEM user to create the database through the application and hbm2ddl.</p> <p>Anyone knows why this fails? SYSTEM seems to have all provileges on the other schemas too, perhaps I'm missing something in the annotation for Oracle that Postgres does not require?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload