Hi,
when i execute the following method everythings works ok:
public List
readTeacherByExecutionCourseProfessorship(IDisciplinaExecucao
executionCourse) throws ExcepcaoPersistencia {
try {
ITeacher teacher = null;
String oqlQuery = "select teacher from " +
Teacher.class.getName();
oqlQuery += " where
professorShipsExecutionCourses.executionPeriod.executionYear.year = $1";
oqlQuery += " and professorShipsExecutionCourses.sigla = $2";
oqlQuery += " and
professorShipsExecutionCourses.executionPeriod.name =
$3";
query.create(oqlQuery);
query.bind(executionCourse.getExecutionPeriod().getExecutionYear().getYear()
);
query.bind(executionCourse.getSigla());
query.bind(executionCourse.getExecutionPeriod().getName());
List result = (List) query.execute();
lockRead(result);
return result;
} catch (Exception ex) {
throw new ExcepcaoPersistencia(ExcepcaoPersistencia.QUERY,
ex);}}
but if the order of the query is different, for example:
public List
readTeacherByExecutionCourseProfessorship(IDisciplinaExecucao
executionCourse) throws ExcepcaoPersistencia {
try {
ITeacher teacher = null;
String oqlQuery = "select teacher from " +
Teacher.class.getName();
oqlQuery += " where professorShipsExecutionCourses.sigla = $1";
oqlQuery += " and
professorShipsExecutionCourses.executionPeriod.name =
$2";
oqlQuery += " and
professorShipsExecutionCourses.executionPeriod.executionYear.year = $3";
query.create(oqlQuery);
query.bind(executionCourse.getSigla());
query.bind(executionCourse.getExecutionPeriod().getName());
query.bind(executionCourse.getExecutionPeriod().getExecutionYear().getYear()
);
List result = (List) query.execute();
lockRead(result);
return result;
} catch (Exception ex) {
throw new ExcepcaoPersistencia(ExcepcaoPersistencia.QUERY,
ex);}}
I catch the follwoing error:
[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR: SQLException
during the execution of the query (for a Dominio.Teacher): Invalid
argument value: Not unique table/alias: 'A1'
Invalid argument value: Not unique table/alias: 'A1'
java.sql.SQLException: Invalid argument value: Not unique table/alias: 'A1'
at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
at com.mysql.jdbc.Connection.execSQL(Unknown Source)
at com.mysql.jdbc.PreparedStatement.executeQuery(Unknown Source)
at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown
Source)
at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown Source)
at
org.apache.ojb.broker.singlevm.RsIteratorFactoryImpl.createRsIterator(Unknow
n Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getRsIteratorFromQuery(
Unknown Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getIteratorFromQuery(Un
known Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
known Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
known Source)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Un
known Source)
at
org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.getCollectionByQu
ery(Unknown Source)
at org.apache.ojb.odmg.oql.OQLQueryImpl.execute(Unknown Source)
at
ServidorPersistente.OJB.TeacherOJB.readTeacherByExecutionCourseProfessorship
(TeacherOJB.java:157)
I have this class:
public class Teacher implements ITeacher {
private Integer idInternal;
private Integer teacherNumber;
private List professorShipsExecutionCourses;
private IPessoa person;
private Integer keyPerson;
and the following mapping :
<class-descriptor
class="Dominio.Teacher"
table="TEACHER">
<field-descriptor id="1"
name="idInternal"
column="ID_INTERNAL"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor id="2"
name="teacherNumber"
column="TEACHER_NUMBER"
jdbc-type="INTEGER"
/>
<field-descriptor id="3"
name="keyPerson"
column="KEY_PERSON"
jdbc-type="INTEGER"
/>
<reference-descriptor
name="person"
class-ref="Dominio.Pessoa"
proxy="true"
>
<foreignkey field-id-ref="3"/>
</reference-descriptor>
<collection-descriptor
name="professorShipsExecutionCourses"
element-class-ref="Dominio.DisciplinaExecucao"
indirection-table="PROFESSORSHIPS"
auto-retrieve="true"
>
<fk-pointing-to-this-class column="ID_TEACHER"/>
<fk-pointing-to-element-class column="ID_EXECUTIONCOURSE"/>
</collection-descriptor>
</class-descriptor>
this is the sql to create the tables :
#----------------------------
# Table structure for professorships
#----------------------------
create table PROFESSORSHIPS (
INTERNAL_CODE integer(11) not null auto_increment,
ID_TEACHER int(11) unsigned not null default '0',
ID_EXECUTIONCOURSE int(11) unsigned not null default '0',
primary key (INTERNAL_CODE),
UNIQUE KEY U1(ID_TEACHER, ID_EXECUTIONCOURSE))
type=InnoDB comment="InnoDB free: 372736 kB";
#----------------------------
# Table structure for TEACHER
#----------------------------
create table TEACHER (
ID_INTERNAL int(11) unsigned not null auto_increment,
TEACHER_NUMBER int(10) unsigned,
KEY_PERSON int(11) unsigned not null,
primary key (ID_INTERNAL),
UNIQUE KEY U1 (TEACHER_NUMBER,KEY_PERSON))
type=InnoDB comment="InnoDB free: 372736 kB";
Thanks in advance,
Jo�o Mota
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]