db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joose Vettenranta <jo...@iki.fi>
Subject Re: BUG(?): 2 classes, same table name, different database
Date Fri, 19 Nov 2004 07:41:49 GMT

 > AFAIK all persistent object related mappings (in OJB metadata classes)
 > based on class name not on table name, so your problem should not
 > happen. Nevertheless seems it does.
 > Could you post more details, e.g. a code snip where the problem  
happens.

I have code like this;

    Admin admin = new Admin();
    Criteria criteria = new Criteria ();
    criteria.addEqualTo ("password", password);
    Criteria criteria2 = new Criteria ();
    criteria2.addEqualTo ("username",login);
    criteria.addAndCriteria (criteria2);

    QueryByCriteria query = QueryFactory.newQuery (admin.getClass(),  
criteria, true);

    dao = new SimpleDAO (factory, "isurvey");

    Collection col = dao.retrieve (query); // <- SQLException


And that dao.retrieve has something like this code:

	public Collection retrieve (QueryByCriteria query) {
			....
			broker =  
PersistenceBrokerFactory.createPersistenceBroker(connection,"","");
			broker.beginTransaction();
			results = broker.getCollectionByQuery(query);
			broker.commitTransaction();
			broker.close();
			....
			return results;
	}

Repository.xml:

         <jdbc-connection-descriptor jcd-alias="db1"  
default-connection="false" platform="PostgreSQL"  
subprotocol="postgresql">
                 <sequence-manager  
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImp 
l"/>
                         <object-cache  
class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
                                 <attribute attribute-name="timeout"  
attribute-value="900"/>
                                 <attribute attribute-name="autoSync"  
attribute-value="true"/>
                                 <attribute  
attribute-name="cachingKeyType" attribute-value="1"/>
                                 </object-cache>
         </jdbc-connection-descriptor>
         <jdbc-connection-descriptor jcd-alias="db2"  
default-connection="false" platform="PostgreSQL"  
subprotocol="postgresql">
                 <sequence-manager  
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImp 
l"/>
                         <object-cache  
class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
                                 <attribute attribute-name="timeout"  
attribute-value="900"/>
                                 <attribute attribute-name="autoSync"  
attribute-value="true"/>
                                 <attribute  
attribute-name="cachingKeyType" attribute-value="1"/>
                                 </object-cache>
         </jdbc-connection-descriptor>

                 <class-descriptor  
class="net.vettenranta.db1.admin.bean.AdminImpl" table="admins">
                         <field-descriptor name="uid" primarykey="true"  
nullable="false" default-fetch="true" column="uid" jdbc-type="VARCHAR"  
/>
                         <field-descriptor name="password"  
nullable="false" default-fetch="true" column="password"  
jdbc-type="VARCHAR" />
                 </class-descriptor>

         <class-descriptor class="net.vettenranta.db2.bean.Admin"  
table="admins">
                 <field-descriptor name="id" primarykey="true"  
nullable="false" default-fetch="true" autoincrement="true" column="ID"  
sequence-name="admins_id_seq" jdbc-type="INTEGER"/>
                 <field-descriptor name="username" default-fetch="true"  
column="username" jdbc-type="VARCHAR" />
                 <field-descriptor name="password" default-fetch="true"  
column="password" jdbc-type="VARCHAR" />
                 <field-descriptor name="name" default-fetch="true"  
column="name" jdbc-type="VARCHAR" />
                 <field-descriptor name="email" default-fetch="true"  
column="email" jdbc-type="VARCHAR"  />
                 <collection-descriptor name="users"  
element-class-ref="net.vettenranta.db2.bean.User" auto-update="true"  
auto-delete="true" auto-retrieve="true">
                         <inverse-foreignkey field-ref="admin_id"/>
                 </collection-descriptor>
         </class-descriptor>

Error msg related to ojb:
[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR: SQLException  
during the execution of the query (for a  
com.intertechnika.isurvey.survey.bean.Admin): ERROR:  No such attribute  
a0.uid

ERROR:  No such attribute a0.uid

java.sql.SQLException: ERROR:  No such attribute a0.uid

at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:126)     
     at  
org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connec 
tion.java:451)        at  
org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Stateme 
nt.java:281)        at  
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Stateme 
nt.java:48)        at  
org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1St 
atement.java:144)        at  
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown  
Source)        at  
org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(Unknown  
Source)        at  
org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown Source)      
    at  
org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknow 
n Source)        at  
org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery( 
Unknown Source)        at  
org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Un 
known Source)        at  
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk 
nown Source)        at  
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk 
nown Source)        at  
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk 
nown Source)        at  
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Un 
known Source)        at  
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQu 
ery(Unknown Source)        at  
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQu 
ery(Unknown Source)
......
org.apache.ojb.broker.PersistenceBrokerSQLException:  
java.sql.SQLException: ERROR:  No such attribute a0.uid        at  
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown  
Source)        at  
org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(Unknown  
Source)        at  
org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown Source)      
    at  
org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknow 
n Source)        at  
org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery( 
Unknown Source)        at  
org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Un 
known Source)        at  
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk 
nown Source)        at  
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk 
nown Source)        at  
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unk 
nown Source)        at  
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Un 
known Source)        at  
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQu 
ery(Unknown Source)        at  
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQu 
ery(Unknown Source)

PostgreSQL log:
Using db1:

SELECT DISTINCT A0.password,A0.uid,A0.username,A0.email,A0.name,A0.ID  
FROM admins A0 WHERE A0.password = 'xxxx'

^- yeah, little bug in my software for not getting username to where  
clause =), but still, as you can see, it takes way more fields than it  
should.

Using db2:
SELECT DISTINCT A0.password,A0.uid,A0.username,A0.email,A0.name,A0.ID  
FROM admins A0 WHERE ( A0.password = 'xxx') AND  (A0.username = 'xxx')

 > How could a test case for your problem look like?
 > - Obtain PB instance for db1 and store AdminImpl object, close this  
PB.
 > - Then obtain PB instance for db2 and store an Admin object --> this  
fails.

Well, I don't even have to use db1 to get that bug. It is enough that  
it is in my repository.xml (commenting AdminImpl away, Admin works and  
vice versa).

ps. when you answer, could you include me to receivers because I'm not  
subscribed on dev-list.

Thanks,

Joose

--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message