I'm sorry Eric, maybe my explanation has been a little to short.

The attribute SEQ_{0} is a placeholder that automaticaly replaces {0} with your table name. In your case you need to replace SEQ_{0} with the name of the sequence you created on oracle or setup your sequence as follows:

CREATE SEQUENCE SEQ_WWW_PATIENT_COMMENTS MAXVALUE 2147483647
INCREMENT BY 1 START WITH 1
/
CREATE TRIGGER TRG_WWW_PATIENT_COMMENTS
BEFORE INSERT OR UPDATE ON WWW_PATIENT_COMMENTS
FOR EACH ROW
DECLARE
   iCounter WWW_PATIENT_COMMENTS.pat_comment_id%TYPE;
   cannot_change_counter EXCEPTION;
BEGIN
   IF INSERTING THEN
       Select SEQ_WWW_PATIENT_COMMENTS.NEXTVAL INTO iCounter FROM Dual;
       :new.pat_comment_id := iCounter;
   END IF;

   IF UPDATING THEN
       IF NOT (:new.pat_comment_id = :old.pat_comment_id) THEN
           RAISE cannot_change_counter;
       END IF;
   END IF;

EXCEPTION
    WHEN cannot_change_counter THEN
        raise_application_error(-20000, 'Cannot Change Counter Value');
END;
/

You also may have a look at: http://castor.codehaus.org/key-generator.html

The VALUES (?,?,?,?,?,?) is correct as the ? will be replaced with the values that need to be inserted into the database.

Ralf


Eric Anderson schrieb:

<key-generator name="SEQUENCE" alias="www_patient_comments_seq">
       <param name="sequence" value="SEQ_{0}" />
       <param name="returning" value="true" />
       <param name="trigger" value="true" />
   </key-generator>


and


System.out.println("Comment: "+cForm.getComment()+"
"+cForm.getPatientId()+" "+cForm.getPatCommentId());
create(cForm);

returns

Comment: test again jan4.05.test1 null
Apr 5, 2005 3:18:49 PM org.exolab.castor.jdo.engine.SQLEngine create
SEVERE: A fatal error occurred while creating
org.usiis.struts.CommentForm using
SQL: {call INSERT INTO "WWW_PATIENT_COMMENTS"
("USIIS_ID","PATIENT_ID","PROVIDE
R_ID","DATE_CREATED","PAT_COMMENT","SHARE_FLAG") VALUES (?,?,?,?,?,?)
RETURNING
"PAT_COMMENT_ID" INTO ?}
java.sql.SQLException: ORA-01400: cannot insert NULL into
("HL_AIMS"."WWW_PATIEN
T_COMMENTS"."PAT_COMMENT_ID")
ORA-06512: at line 1

       at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:124)
       at
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
       at
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
       at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:622)
       at
oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.



Is the VALUES (?,?,?,?,?,?)  the problem? Although I don't know why
they would all be ?

thanks




[EMAIL PROTECTED] 04/05/05 03:10PM >>>


I use following key-generator definition with oracle.

   <key-generator name="SEQUENCE" alias="PCV">
       <param name="sequence" value="SEQ_{0}" />
       <param name="returning" value="true" />
       <param name="trigger" value="true" />
   </key-generator>

Could you try to add the trigger tag.

Ralf


Eric Anderson schrieb:



Yup it creats fine with an artifical key. So what could be wrong with
this sequence...

Creates fine with a insert statement in oracle. I have checked
spelling.





[EMAIL PROTECTED] 04/05/05 12:15PM >>>




My first bet is something with the key-generator is screwy. Can you
take that out and see if it will work correctly (just fake the key on
one)? Everything else looks fine.

As far as the logging go, are you using Log4j at all? If so you can
set the default logging in the properties file to DEBUG for


org.exolab


and also change the property in the castor.properties file which is


in


the castor jar file. (forget which one, but its clearly commented)

On Apr 5, 2005 1:48 PM, Eric Anderson <[EMAIL PROTECTED]> wrote:




Seems as though I have another newbie problem

public void create(Object object) throws Exception {
  Database db = null;
  try {
    db = getDatabase();
    db.begin();
    db.create(object);
    db.commit();
  }
  catch (Exception e) {
    db.rollback();
    throw e;
  }
  finally {
    close(db);
  }
}

When I call create(cForm); the java process goes to 99% and hangs




until




I kill it. Is there some kind of logging I can turn on to see where




it




is hanging?
I am using castor-0.9.5.3.jar and classes12 from oracle 10g (thin
client)

Here is the mapping.

<key-generator name="SEQUENCE" alias="www_patient_comments_seq">
<param name="sequence" value="www_patient_comments_seq"/>
<param name="returning" value="true"/>
</key-generator>
<!-- comments area -->
<class name="org.usiis.struts.CommentForm" identity="patCommentId"
key-generator="www_patient_comments_seq">
<!--<cache-type type="unlimited"/>-->
<map-to table="WWW_PATIENT_COMMENTS"/>
<field name="patCommentId" type="integer"><sql
name="pat_comment_id" type="integer"/></field>
<field name="usiisId" type="string"><sql name="usiis_id"
type="integer"/></field>
<field name="patientId" type="string"><sql name="patient_id"
type="char"/></field>
<field name="providerId" type="string"><sql




name="provider_id"




type="char"/></field>
      <field name="date" type="date"><sql name="date_created"
type="date"/></field>
      <field name="comment" type="string"><sql name="pat_comment"
type="char"/></field>
      <field name="share" type="boolean"><sql name="share_flag"
type="char[NY]"/></field>
</class>









Reply via email to