Note that there are some explanatory texts on larger screens.

plurals
  1. POhelp creating schema sql for hsqldb
    primarykey
    data
    text
    <p>I am quite new to database programming and am trying to create a java program to access <em>hsqldb</em>(version2.2.5) using hibernate.I have 3 classes in my program which I mapped to 3 tables as given below.</p> <p>I wanted to create a <em>one-to-one mapping</em> between SaleOrder and Bill. Also, to create a schema for the db, I tried sql create statements. The two tables SALEORDER and BILL have each other's id as a FK.To avoid dependency error between tables during create,I used <em>alter table add constraint</em> statements</p> <p>Now,I want to use drop table statements at the beginning of script.I used the following</p> <pre><code>ALTER TABLE SALEORDER DROP CONSTRAINT FK_SO_BILL; ALTER TABLE SALEORDER DROP CONSTRAINT FK_SO_BUYER; ALTER TABLE BILL DROP CONSTRAINT FK_BILL_SO; ALTER TABLE BILL DROP CONSTRAINT FK_BILL_BUYER; DROP TABLE BUYER IF EXISTS; DROP TABLE SALEORDER IF EXISTS; DROP TABLE BILL IF EXISTS; </code></pre> <p>This however, causes problem when run for the first time(since the to be altered tables don't exist.).I could not find <em>'IF EXISTS'</em> clause for <em>ALTER TABLE</em> in hsqldb ..So what is the solution?Should I run the create table scripts alone the first time,and add the alter table,drop table statements shown above thereafter?That doesn't sound a clean way.</p> <p>will be grateful for your suggestions,</p> <p>sincerely,</p> <p>Jim </p> <p>The main schema script is </p> <pre><code>CREATE TABLE BUYER( BUYER_ID BIGINT NOT NULL PRIMARY KEY IDENTITY, NAME VARCHAR(100) ); CREATE TABLE SALEORDER( SALEORDER_ID BIGINT NOT NULL PRIMARY KEY IDENTITY, BUYER_ID BIGINT NOT NULL, BILL_ID BIGINT, ); CREATE TABLE BILL( BILL_ID BIGINT NOT NULL PRIMARY KEY IDENTITY, BUYER_ID BIGINT NOT NULL, SALEORDER_ID BIGINT NOT NULL, ); ALTER TABLE SALEORDER ADD CONSTRAINT FK_SO_BILL FOREIGN KEY(BILL_ID) REFERENCES BILL(BILL_ID); ALTER TABLE SALEORDER ADD CONSTRAINT FK_SO_BUYER FOREIGN KEY(BUYER_ID) REFERENCES BUYER(BUYER_ID); ALTER TABLE BILL ADD CONSTRAINT FK_BILL_BUYER FOREIGN KEY(BUYER_ID) REFERENCES BUYER(BUYER_ID); ALTER TABLE BILL ADD CONSTRAINT FK_BILL_SO FOREIGN KEY(SALEORDER_ID) REFERENCES SALEORDER(SALEORDER_ID); </code></pre> <p>Also,I am using an ant target to create schema</p> <pre><code>&lt;target name="createschema" description="execute schema"&gt; &lt;sql driver="${db.driver}" url="${db.url}" userid="${db.username}" password="${db.password}" print="yes" src="${dir.schema}/${file.schema}" caching="false" showheaders="true" &gt; &lt;classpath&gt; &lt;path location="${dir.lib}/hsqldb.jar"/&gt; &lt;/classpath&gt; &lt;/sql&gt; &lt;/target&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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