Hi,
I'm trying to use OJB in a project for my college diploma (and I'm
runnig out of time...). Now I can't go on because of an error. Maybe I
should better use ODMG instead of JDO? If you have any ideas... Please
help me.
Now I encountered a strange error. In one of my tables I can't insert
anything, because some (not all) attributes of the persistent object are
suddenly null. It happens when manager.makePersistent() is called. Then
the insert is rejected because the these fields cannot be null and the
database is throwing an exception.
With other tables it's working fine. A debugger session showed that my
persistent object "Curriculum" has all the attributes set with correct
values. But when manager.makePersistent(c) is executed, the attributes
nAME and sEASON_ID are suddenly null.
Configuration:
OJB 0.9.4 (will try 0.9.5 tomorrow)
Sun JRE 1.3.1_01a
HSQLDB 1.7.0
OJB in single VM mode,
SequenceManagerClass=org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl
JDO Interface
Persistent classes and repository.xml generated with a modified
org.apache.ojb.tools.mapping.reversedb
Exception:
[org.apache.ojb.broker.accesslayer.JdbcAccess] ERROR: SQLException
during the execution of the insert: Try to insert null into a
non-nullable column: 23000 Try to insert null into a non-nullable column
in statement [INSERT INTO CURRICULUM (ID,NAME,SEASON_ID,STUDY_ID,YEAR)
VALUES ( 181, NULL, NULL, 3, 1998 ) ]
...
at org.hsqldb.Trace.getError(Trace.java:226)
at org.hsqldb.Result.<init>(Result.java:154)
at org.hsqldb.jdbcConnection.executeHSQL(jdbcConnection.java:2821)
at org.hsqldb.jdbcConnection.execute(jdbcConnection.java:2536)
at org.hsqldb.jdbcStatement.fetchResult(jdbcStatement.java:1804)
at org.hsqldb.jdbcStatement.executeUpdate(jdbcStatement.java:227)
at
org.hsqldb.jdbcPreparedStatement.executeUpdate(jdbcPreparedStatement.java:419)
at
org.apache.ojb.broker.accesslayer.JdbcAccess.executeInsert(Unknown Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
at org.apache.ojb.jdo.PersistenceManagerImpl.makePersistent(Unknown
Source)
at og.timetable.tools.DBTool.createCurriculum(DBTool.java:63)
at og.timetable.tools.DBTool.setupDB(DBTool.java:33)
at og.timetable.tools.DBTool.<init>(DBTool.java:27)
at og.timetable.tools.DBTool.main(DBTool.java:166)
org.apache.ojb.broker.PersistenceBrokerSQLException
at
org.apache.ojb.broker.accesslayer.JdbcAccess.executeInsert(Unknown Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Unknown Source)
at org.apache.ojb.jdo.PersistenceManagerImpl.makePersistent(Unknown
Source)
at og.timetable.tools.DBTool.createCurriculum(DBTool.java:63)
at og.timetable.tools.DBTool.setupDB(DBTool.java:33)
at og.timetable.tools.DBTool.<init>(DBTool.java:27)
at og.timetable.tools.DBTool.main(DBTool.java:166)
Exception in thread "main"
Code:
public class DBTest {
...
private void createCurriculum(){
Transaction tx = null;
tx = manager.currentTransaction();
tx.begin();
Curriculum c = new Curriculum();
c.setNAME("Test");
c.setSTUDY_ID(new Long(3)); // test value
c.setSEASON_ID(new Long(1)); // test value
c.setYEAR(1998);
manager.makePersistent(c);
// exception happens here, suddenly c.nAME and c.sEASON_ID = null
tx.commit();
}
private void initOJB() {
manager = null;
try {
factory = PersistenceManagerFactoryImpl.getInstance();
manager = factory.getPersistenceManager();
}
catch (Throwable t) {
System.out.println("ERROR: " + t.getMessage());
t.printStackTrace();
}
}
}
public class Curriculum
{
private Long iD;
private String nAME;
private Long sEASON_ID;
private Long sTUDY_ID;
private int yEAR;
private og.timetable.persistent.Study aStudy;
private og.timetable.persistent.Season aSeason;
private java.util.Vector collSemester;
...
}
repository.xml:
...
<class-descriptor
class="og.timetable.persistent.Curriculum"
table="CURRICULUM"
>
<field-descriptor id="0"
name="iD"
column="ID"
jdbc-type="BIGINT"
primarykey="true"
autoincrement="true"
/>
<field-descriptor id="1"
name="nAME"
column="NAME"
jdbc-type="VARCHAR"
/>
<field-descriptor id="2"
name="sEASON_ID"
column="SEASON_ID"
jdbc-type="BIGINT"
/>
<field-descriptor id="3"
name="sTUDY_ID"
column="STUDY_ID"
jdbc-type="BIGINT"
/>
<field-descriptor id="4"
name="yEAR"
column="YEAR"
jdbc-type="INTEGER"
/>
<reference-descriptor
name="aStudy"
class-ref="og.timetable.persistent.Study"
auto-retrieve="true"
auto-update="false"
auto-delete="false"
>
<foreignkey field-id-ref="3"/>
</reference-descriptor>
<reference-descriptor
name="aSeason"
class-ref="og.timetable.persistent.Season"
auto-retrieve="true"
auto-update="false"
auto-delete="false"
>
<foreignkey field-id-ref="2"/>
</reference-descriptor>
<collection-descriptor
name="collSemester"
element-class-ref="og.timetable.persistent.Semester"
auto-retrieve="true"
auto-update="false"
auto-delete="false"
>
<inverse-foreignkey field-id-ref="1"/>
</collection-descriptor>
</class-descriptor>
...
SQL:
CREATE TABLE Curriculum (
ID BIGINT NOT NULL,
Name VARCHAR(60) NOT NULL,
Season_id BIGINT NOT NULL,
Study_id BIGINT NOT NULL,
Year INTEGER NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (Season_id)
REFERENCES Season,
FOREIGN KEY (Study_id)
REFERENCES Study
);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>