Re: Inheritance problem with association...
What sequence manager do you use, i.e. who is creating the primary keys ? Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Inheritance problem with association...
I have dug into the OJB code a little bit. I'm looking in this method of org.apache.ojb.broker.Identity: private void init(Object objectToIdentify, PersistenceBroker targetBroker, ClassDescriptor cld) It looks like the child class (ClientPayrollDeductionPlan) is getting an id (lets say id=1), and then the parent class (PayrollDeductionClass) is getting the next id (id=2). The associated classes (PayPlanAssociation) are using the first id (id=1) for their foreign key. However when the parent class gets stored in the database, both it and the child have the second id (id=2), but all of the associated classes have the foreign key equal to the first one (1). I hope that made sense. Shouldn't the Parent class, and the child class both have the same id? (They do when they get inserted, but not when the associated class is getting it's foreign keys assigned). Am I looking in the right area? Is there anything else I should be looking at? On Tue, 1 Feb 2005 09:59:17 -0600, Wesley Lemke [EMAIL PROTECTED] wrote: We have a a problem with OJB assigning incorrect id's. This is the situation: public class PayrollDeductionPlan { Long id; String genericInfo = Generic; // List of PayPlanAssociations List assocs = new ArrayList(); } public class ClientPayrollDeductionPlan extends PayrollDeductionPlan { Long id; String clientInfo = Client; } public class PayPlanAssociation { Long id; // Reference to PayRollDeductionPlan PayrollDeductionPlan plan; } Here is the repository.xml file: class-descriptor class=model.PayrollDeductionPlan table=dexa810t field-descriptor name=id column=a_id jdbc-type=BIGINT primarykey=true autoincrement=true / field-descriptor name=genericInfo column=generic_info jdbc-type=VARCHAR / collection-descriptor name=assocs element-class-ref=model.PayPlanAssociation auto-delete=true auto-update=true inverse-foreignkey field-ref=plan / /collection-descriptor /class-descriptor class-descriptor class=model.ClientPayrollDeductionPlan table=dexa820t field-descriptor name=id column=b_id jdbc-type=BIGINT primarykey=true autoincrement=true / field-descriptor name=clientInfo column=client_info jdbc-type=VARCHAR / reference-descriptor name=super class-ref=model.PayrollDeductionPlan auto-retrieve=true auto-update=true auto-delete=true foreignkey field-ref=id/ /reference-descriptor /class-descriptor class-descriptor class=model.PayPlanAssociation table=dexa830t field-descriptor name=id column=d_id jdbc-type=BIGINT primarykey=true autoincrement=true / field-descriptor name=plan column=a_id jdbc-type=BIGINT access=anonymous / reference-descriptor name=plan class-ref=model.PayrollDeductionPlan foreignkey field-ref=plan/ /reference-descriptor /class-descriptor When I do something like this: PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(default, user, password); broker.beginTransaction(); // Create new ClientPayrollDeductionPlan ClientPayrollDeductionPlan plan = new ClientPayrollDeductionPlan(); // Add 5 PayPlanAssociations to this PayrollDeductionPlan for(int i = 0; i 5; i++){ // Create new PayPlanAssociation PayPlanAssociation ppa = new PayPlanAssociation(); // Create link between PayPlanAssociation and PayrollDeductionPlan plan.getAssocs().add(ppa); ppa.setPlan(plan); } broker.store(plan); broker.commitTransaction(); broker.close(); This is what I get in the tables: mysql select * from dexa810t; (PayrollDeductionPlan) +--+--+ | a_id | generic_info | +--+--+ | -3 | Generic | +--+--+ 1 row in set (0.05 sec) mysql select * from dexa820t; (ClientPayrollDeductionPlan); +--+-+ | b_id | client_info | +--+-+ | -3 | Client | +--+-+ 1 row in set (0.00 sec) mysql select * from dexa830t; (PayPlanAssociation) +--+--+ | d_id | a_id | +--+--+ | -4 | -2 | | -5 | -2 | | -6 | -2 | | -7 | -2 | | -8 | -2 | +--+--+ 5 rows in set (0.03 sec) The foreign key in the PayPlanAssociation table is always one off from what it should be... (-2 instead of -3). This problem happens in
Re: Inheritance problem with association...
I think that when you map inheritance to multiple tables, and use a native (database) sequence manager for generating the ids, you have to make sure yourself that the entries in the different tables get the same primarykey. If you use a app-space sequence manager (nextval for example), then OJB should do this for you. I'm sorry that I can't help you more, but my experience with mapping using super-references is limited, and in an EJB environment even more. You could search the user mailing list archives for application server and sequence manager or mapping to multiple tables. Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Inheritance Problem.
Hello Ziv, In persisting the parent class OJB has to instantiate it (using log4j you see the exact position if you set the logging to DEBUG in theOJB.properties). Since this can't be done with an abstract class, the described error occurs. Working around the same error we decided to make the abstract class concrete and have a log entry in the constructor, so we can check it`s instantiations. Another way would be to map each implementation to a different table, thus treating the abstact class like an interface. Perhaps there should be a warning in tutorial 3 (Advanced O/R) about this restriction. Regards, Birgitta Ziv Yankowitz wrote: Folks, we need to map an abstract class and it's implementation to two different tables we tried the following : abstract class A { private id private valueA protected ojbConcreteClass } class B extends A{ private id2 private valueB } the repository file: class-descriptor class=A table=A_TABLE field-descriptor name=id column=ID jdbc-type=INTEGER primarykey=true autoincrement=true / field-descriptor name=valueA column=VALUE jdbc-type=INTEGER / /class-descriptor class-descriptor class=B table=B_TABLE field-descriptor name=id2 column=ID jdbc-type=INTEGER primarykey=true autoincrement=true / field-descriptor name=valueB column=VALUE jdbc-type=INTEGER / field-descriptor name=ojbConcreteClass column=CLASS_NAME jdbc-type=VARCHAR / reference-descriptor name=super class-ref=A auto-update=true foreignkey field-ref=id2/ /reference-descriptor /class-descriptor we encounter in the following error: org.apache.ojb.broker.PersistenceBrokerException: org.apache.ojb.broker.metadata.MetadataException: java.lang.Instantiat ionException what are we doing wrong ?
RE: Inheritance Problem.
Thanks for the response. If I understand correctly there is no way we can map the abstract class to it's own table. Thanks again for the response. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, February 26, 2004 8:52 AM To: OJB Users List Subject: Re: Inheritance Problem. Hello Ziv, In persisting the parent class OJB has to instantiate it (using log4j you see the exact position if you set the logging to DEBUG in theOJB.properties). Since this can't be done with an abstract class, the described error occurs. Working around the same error we decided to make the abstract class concrete and have a log entry in the constructor, so we can check it`s instantiations. Another way would be to map each implementation to a different table, thus treating the abstact class like an interface. Perhaps there should be a warning in tutorial 3 (Advanced O/R) about this restriction. Regards, Birgitta Ziv Yankowitz wrote: Folks, we need to map an abstract class and it's implementation to two different tables we tried the following : abstract class A { private id private valueA protected ojbConcreteClass } class B extends A{ private id2 private valueB } the repository file: class-descriptor class=A table=A_TABLE field-descriptor name=id column=ID jdbc-type=INTEGER primarykey=true autoincrement=true / field-descriptor name=valueA column=VALUE jdbc-type=INTEGER / /class-descriptor class-descriptor class=B table=B_TABLE field-descriptor name=id2 column=ID jdbc-type=INTEGER primarykey=true autoincrement=true / field-descriptor name=valueB column=VALUE jdbc-type=INTEGER / field-descriptor name=ojbConcreteClass column=CLASS_NAME jdbc-type=VARCHAR / reference-descriptor name=super class-ref=A auto-update=true foreignkey field-ref=id2/ /reference-descriptor /class-descriptor we encounter in the following error: org.apache.ojb.broker.PersistenceBrokerException: org.apache.ojb.broker.metadata.MetadataException: java.lang.Instantiat ionException what are we doing wrong ? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: inheritance problem
Hi, I had a similar problem. You may want to have a look at the Problem mapping inheritance hierarchy using joined tables for subclasses thread on this list (last post 2003-12-05) or at the Extents and the various inheritance hierarchy mappings thread at the dev-list. I do not think, this is fixed in rc5. If you want to materialize the sub-class, it needs to be declared as extent of the superclass. Yet, it is not possible to use extent defintions for joined subclasses if primary keys serve as foreign key in the subclass. It may work if you have an additional foreign-key column in your subclass (making the primary keys unique). Peter Hi, I'm trying to map inheritance to multiple joined tables, but something is going wrong. It inserts ok, but when loading, it materializes the superclass, instead of subclass. Important: 1) I am NOT using extents; 2) I am not declaring attributes (_id, in this case, which is is primary key and serves also as foreign key) in the subclass in the object model. 3) I have tried the anonymous field approach, but it materializes the superclass too. I believe I am facing a configuration mistake, so these are the class-descriptors: !--SUPERCLASS -- class-descriptor class=com.jma.interescola.core.User table=user_1 field-descriptor id=1 name=_id column=id jdbc-type=INTEGER primarykey=true autoincrement=true/ field-descriptor id=2 name=_name column=name jdbc-type=VARCHAR/ /class-descriptor !--SUBLASS -- class-descriptor class=com.jma.interescola.core.Student table=student field-descriptor id=1 name=_id column=id jdbc-type=INTEGER primarykey=true autoincrement=true/ reference-descriptor auto-retrieve=true auto-update=true auto-delete=true name=super class-ref=com.jma.interescola.core.User foreignkey field-ref=_id/ /reference-descriptor /class-descriptor Please, any help or suggestion would be great. If this is a bug, anyone knows if the release rc5 fixed it? Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Inheritance problem
hi balza? , ojb is not able to find the fields defined in the superclass. this problem was fixed some time ago. there are also testcases in AnonymousFieldTest that successfully query fields in superclass. please get the latest from repository. hth jakob balza wrote: Hello, * the class-descriptors: class-descriptor class=allibo.core.Account table=c_account field-descriptor name=account_id column=account_id jdbc-type=INTEGER primarykey=true autoincrement=true/ field-descriptor name=login column=login jdbc-type=VARCHAR/ field-descriptor name=password column=password jdbc-type=VARCHAR/ field-descriptor name=first_name column=first_name jdbc-type=VARCHAR/ field-descriptor name=last_name column=last_name jdbc-type=VARCHAR/ field-descriptor name=gender column=gender jdbc-type=VARCHAR/ field-descriptor name=remark column=remark jdbc-type=VARCHAR/ field-descriptor name=email column=email jdbc-type=VARCHAR/ field-descriptor name=registration_date column=registration_date jdbc-type=DATE/ field-descriptor name=last_activity_date column=last_activity_date jdbc-type=DATE/ field-descriptor name=date_of_birth column=date_of_birth jdbc-type=DATE/ /class-descriptor class-descriptor class=allibo.commerce.Employee table=fem_employee field-descriptor name=account_id column=account_id jdbc-type=INTEGER primarykey=true autoincrement=true/ reference-descriptor name=super class-ref=allibo.core.Account auto-retrieve=true auto-update=true auto-delete=true foreignkey field-ref=account_id/ /reference-descriptor /class-descriptor public class Account { public Organization organization; public AccountAddress accountAddress; private int account_id; private String login; private String password; private String first_name; private String last_name; private String gender; private String remark; private String email; private Date registration_date; private Date last_activity_date; private Date date_of_birth; + setter getter methods public class Employee extends Account { private int account_id; private Account account; + setter getter methods * The code: public void apply() { //Query OJB Criteria crit = new Criteria(); logger.debug(login : + login); logger.debug(password : + password); crit.addEqualTo(login, login); crit.addEqualTo(password, password); Query q = QueryFactory.newQuery(Employee.class, crit); try { Collection results = broker.getCollectionByQuery(q); Iterator it = results.iterator(); if (it.hasNext()) { employee = (Employee) it.next(); logger.debug(First name + employee.getFirst_name()); } } catch (Throwable t) { t.printStackTrace(); } } * The log 2063 [main] DEBUG allibo.commerce.UCFindEmployeeTest - employee :1082 2073 [main] INFO allibo.commerce.UCFindEmployeeTest - testApply 2073 [main] DEBUG allibo.commerce.UCFindEmployee - login :employee 2073 [main] DEBUG allibo.commerce.UCFindEmployee - password :employee [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.account_id FROM fem_employee A0 WHERE (login = ? ) AND password = ? java.sql.SQLException: Column not found, message from server: Unknown column 'login' in 'where clause' [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR: SQLException during the execution of the query (for a allibo.commerce.Employee): Column not found, message from server: Unknown column 'login' in 'where clause' Column not found, message from server: Unknown column 'login' in 'where clause' at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1626) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:886) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:945) at com.mysql.jdbc.Connection.execSQL(Connection.java:1844) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1458) 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.core.RsIteratorFactoryImpl.createRsIterator(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source) at
Re: Inheritance problem
hi, could you please post the sql used to search and the class-descriptors ? jakob balza wrote: Hello, I've - table tA and tB with an inheritance relationship - class B extending A - class A reflect tA - class B reflect tB insert in class B generate an entry in table tA and in table tB delete or search on table tB generate a java.sql.SQLException: Column not found, message from server: Unknown column 'xxx' in 'where clause' What's wrong? Thank you - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Inheritance problem
Hello, * the class-descriptors: class-descriptor class=allibo.core.Account table=c_account field-descriptor name=account_id column=account_id jdbc-type=INTEGER primarykey=true autoincrement=true/ field-descriptor name=login column=login jdbc-type=VARCHAR/ field-descriptor name=password column=password jdbc-type=VARCHAR/ field-descriptor name=first_name column=first_name jdbc-type=VARCHAR/ field-descriptor name=last_name column=last_name jdbc-type=VARCHAR/ field-descriptor name=gender column=gender jdbc-type=VARCHAR/ field-descriptor name=remark column=remark jdbc-type=VARCHAR/ field-descriptor name=email column=email jdbc-type=VARCHAR/ field-descriptor name=registration_date column=registration_date jdbc-type=DATE/ field-descriptor name=last_activity_date column=last_activity_date jdbc-type=DATE/ field-descriptor name=date_of_birth column=date_of_birth jdbc-type=DATE/ /class-descriptor class-descriptor class=allibo.commerce.Employee table=fem_employee field-descriptor name=account_id column=account_id jdbc-type=INTEGER primarykey=true autoincrement=true/ reference-descriptor name=super class-ref=allibo.core.Account auto-retrieve=true auto-update=true auto-delete=true foreignkey field-ref=account_id/ /reference-descriptor /class-descriptor public class Account { public Organization organization; public AccountAddress accountAddress; private int account_id; private String login; private String password; private String first_name; private String last_name; private String gender; private String remark; private String email; private Date registration_date; private Date last_activity_date; private Date date_of_birth; + setter getter methods public class Employee extends Account { private int account_id; private Account account; + setter getter methods * The code: public void apply() { //Query OJB Criteria crit = new Criteria(); logger.debug(login : + login); logger.debug(password : + password); crit.addEqualTo(login, login); crit.addEqualTo(password, password); Query q = QueryFactory.newQuery(Employee.class, crit); try { Collection results = broker.getCollectionByQuery(q); Iterator it = results.iterator(); if (it.hasNext()) { employee = (Employee) it.next(); logger.debug(First name + employee.getFirst_name()); } } catch (Throwable t) { t.printStackTrace(); } } * The log 2063 [main] DEBUG allibo.commerce.UCFindEmployeeTest - employee :1082 2073 [main] INFO allibo.commerce.UCFindEmployeeTest - testApply 2073 [main] DEBUG allibo.commerce.UCFindEmployee - login :employee 2073 [main] DEBUG allibo.commerce.UCFindEmployee - password :employee [org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: SQL:SELECT A0.account_id FROM fem_employee A0 WHERE (login = ? ) AND password = ? java.sql.SQLException: Column not found, message from server: Unknown column 'login' in 'where clause' [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR: SQLException during the execution of the query (for a allibo.commerce.Employee): Column not found, message from server: Unknown column 'login' in 'where clause' Column not found, message from server: Unknown column 'login' in 'where clause' at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1626) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:886) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:945) at com.mysql.jdbc.Connection.execSQL(Connection.java:1844) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1458) 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.core.RsIteratorFactoryImpl.createRsIterator(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source) at allibo.commerce.UCFindEmployee.apply(UCFindEmployee.java:58) at allibo.commerce.UCFindEmployeeTest.testApply(UCFindEmployeeTest.java:67) at