Re: Crossreferenced Objects
I finally found what was wrong... In fact it is very simple, I was using a database-repository.xml template from a struts tutorial, and there was a static declaration of the cache implementation, thus overriding OJB.properties settings, and it was set with emptyCacheImpl... so that's why crossreferenced objects resulted into stack overflow since this cache doesnt make anything. I set it back to CachePerBroker and it performs well. However, the strange part is that it used to work without any problem in one-threaded test cases before the patch ... Now I can use crossreferenced objects correctly, but now my concern is more on performance side, because all my database objects are crossreferenced objects and are, of course, not retrieved by the same PB, so my question is : Is there a global cache implementation that will be shared by all persistence brokers and thus can be accessed by many threads ? And finally, what about these cache implementation we can find in javadoc in the org.apache.ojb.broker.cache package ? ObjectCachePerClassImpl ObjectCacheSoftImpl Best regards. On Wed, 26 Jan 2005 12:43:20 +0100, Armin Waibel [EMAIL PROTECTED] wrote: Hi Sylvain, I don't know why it happens, maybe I don't understand the problem. The method public StorableObject get(Class objectClass, Integer pk) should return the full materialized object as long as the auto-retrieve settings are true and no proxy was used (e.g. OJB materialize a Room object with all User, each User with it's Room,...). This should not cause an endless loop when lookup the object, because you are using an session cache. Is the stack trace loop within OJB or is your app involved? If you invoke the get(Class objectClass, Integer pk) code in an test case, do the same error happen? If yes, the problem was caused by OJB. In this case please send me your test and I will try to fix it. I think that the source of the problem can be that I don't have any global cache, because I retrieve first the Room Object and the nested collection in a Struts Action (that might be running it it's own thread), and then on the users collection elements I try to get information on rooms, and it runs on a different thread from the first Action since it located in a different Action. hmm, the first time you retrieve an Room or an User object the full object graph should be materialized, so it doesn't matter if different threads try to read object elements. Again please try to write an test case to reproduce the problem (if you think it's a multi-threaded problem run two threads in your test). regards, Armin Sylvain ~ wrote: I tried again to make it work all the day along, When I retrieve objects in Junit test cases, it doesn't give me any error with most of cache implementations... If anyone have any Idea, I am realy thinking this case is hopeless. Here is the full error stack : java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:296) at java.lang.Integer.toString(Integer.java:109) at java.lang.String.valueOf(String.java:2236) at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:558) at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:772) at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:944) at org.apache.ojb.broker.platforms.PlatformDefaultImpl.setObjectForStatement(PlatformDefaultImpl.java:249) at org.apache.ojb.broker.platforms.PlatformMySQLImpl.setObjectForStatement(PlatformMySQLImpl.java:87) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatementValue(StatementManager.java:216) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:248) at org.apache.ojb.broker.accesslayer.StatementManager.bindSelectionCriteria(StatementManager.java:424) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:388) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:361) at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(JdbcAccessImpl.java:279) at org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(RsQueryObject.java:74) at org.apache.ojb.broker.accesslayer.RsIterator.init(RsIterator.java:183) at org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(RsIteratorFactoryImpl.java:58) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(PersistenceBrokerImpl.java:1808) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(PersistenceBrokerImpl.java:1333) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorByQuery(PersistenceBrokerImpl.java:1320) at org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship
Re: Crossreferenced Objects
Thank you for your help, Regards, Sylvain On Wed, 26 Jan 2005 14:16:22 +0100, Armin Waibel [EMAIL PROTECTED] wrote: Hi, Sylvain ~ wrote: I finally found what was wrong... In fact it is very simple, I was using a database-repository.xml template from a struts tutorial, and there was a static declaration of the cache implementation, thus overriding OJB.properties settings, and it was set with emptyCacheImpl... so that's why crossreferenced objects resulted into stack overflow since this cache doesnt make anything. I set it back to CachePerBroker and it performs well. doh! Never use copy paste ;-) However, the strange part is that it used to work without any problem in one-threaded test cases before the patch ... to tell the truth, I don't know. Now I can use crossreferenced objects correctly, but now my concern is more on performance side, because all my database objects are crossreferenced objects and are, of course, not retrieved by the same PB, so my question is : Is there a global cache implementation that will be shared by all persistence brokers and thus can be accessed by many threads ? You can use each global cache in a multithreaded environment. The only problem will be caused by shared object instances. The possibility of dirty-reads and stolen data when multiple threads modify the same object at the same time. http://db.apache.org/ojb/docu/guides/objectcache.html#ObjectCacheDefaultImpl In next version of OJB (1.0.2) a first version of an two-level cache will be included, which will avoid problems described above. You can try latest from CVS (get the OJB_1_0_RELEASE branch, HEAD is OJB 1.1). To generate the docs you need Apache Forrest (0.6 or higher) installed. And finally, what about these cache implementation we can find in javadoc in the org.apache.ojb.broker.cache package ? ObjectCachePerClassImpl ObjectCacheSoftImpl Please see javadoc and source code. Think they aren't smarter then the other implementations. regards, Armin Best regards. On Wed, 26 Jan 2005 12:43:20 +0100, Armin Waibel [EMAIL PROTECTED] wrote: Hi Sylvain, I don't know why it happens, maybe I don't understand the problem. The method public StorableObject get(Class objectClass, Integer pk) should return the full materialized object as long as the auto-retrieve settings are true and no proxy was used (e.g. OJB materialize a Room object with all User, each User with it's Room,...). This should not cause an endless loop when lookup the object, because you are using an session cache. Is the stack trace loop within OJB or is your app involved? If you invoke the get(Class objectClass, Integer pk) code in an test case, do the same error happen? If yes, the problem was caused by OJB. In this case please send me your test and I will try to fix it. I think that the source of the problem can be that I don't have any global cache, because I retrieve first the Room Object and the nested collection in a Struts Action (that might be running it it's own thread), and then on the users collection elements I try to get information on rooms, and it runs on a different thread from the first Action since it located in a different Action. hmm, the first time you retrieve an Room or an User object the full object graph should be materialized, so it doesn't matter if different threads try to read object elements. Again please try to write an test case to reproduce the problem (if you think it's a multi-threaded problem run two threads in your test). regards, Armin Sylvain ~ wrote: I tried again to make it work all the day along, When I retrieve objects in Junit test cases, it doesn't give me any error with most of cache implementations... If anyone have any Idea, I am realy thinking this case is hopeless. Here is the full error stack : java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:296) at java.lang.Integer.toString(Integer.java:109) at java.lang.String.valueOf(String.java:2236) at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:558) at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:772) at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:944) at org.apache.ojb.broker.platforms.PlatformDefaultImpl.setObjectForStatement(PlatformDefaultImpl.java:249) at org.apache.ojb.broker.platforms.PlatformMySQLImpl.setObjectForStatement(PlatformMySQLImpl.java:87) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatementValue(StatementManager.java:216) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:248) at org.apache.ojb.broker.accesslayer.StatementManager.bindSelectionCriteria(StatementManager.java:424
Re: Crossreferenced Objects
I think the problems comes from the cache implementation I use, because It used to work quite well with jUnit tests and Default Cache Implementation, and in this situation there is only One thread so there wasn't any dirty read problem. However, since I moved the application in Struts Actions Under tomcat, I couldn't use the default Cache Implementation since it is not thread-safe, and I got some errors with retrieved data. So, I thought that using a thread-safe cache implementation such as ObjectCachePerBrokerImpl could solve the problem, and by doing so I solved the problems that used to happen, until I tried Crossreferenced Objects... I think that the source of the problem can be that I don't have any global cache, because I retrieve first the Room Object and the nested collection in a Struts Action (that might be running it it's own thread), and then on the users collection elements I try to get information on rooms, and it runs on a different thread from the first Action since it located in a different Action. So, I think that using a global cache which is thread-safe could solve this issue, however there is only few documentation on caches implementations in the cache package. As I read in the javadoc, it seems that ObjectCachePerClassImpl is a global cache, but i don't know if it thread-safe at all. I retrieve Objects using this code : public StorableObject get(Class objectClass, Integer pk) { PersistenceBroker broker = null; Object result; Criteria crit = new Criteria(); crit.addEqualTo(pk,pk); crit = criteraModificator(objectClass, crit); try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); QueryByCriteria query = new QueryByCriteria(objectClass, crit); result = broker.getObjectByQuery(query); } finally { if (broker != null) broker.close(); } return (StorableObject)result; } Regards, Sylvain. On Tue, 25 Jan 2005 11:23:02 +0100, Armin Waibel [EMAIL PROTECTED] wrote: Hi, which version of OJB do you use? Did you try the default ObjectCache implementation? Same result? How does your code look like? regards, Armin Sylvain ~ wrote: Hi, I'm trying to create crossreferenced objects, as specified in the Cache documentation : It allows to perform circular lookups (as by crossreferenced objects) that would result in non-terminating loops without such a cache. I Use ObjectCachePerBrokerImpl since my application is multi-threaded (and runs on tomcat) The problem is that I get a java.lang.StackOverflowError, when trying to do so with theses classes (simplified for clarity). both classes have auto-retrieve=true. Any Idea to make it work would be appreciated. Sylvain. public class User { /** * --- PK --- * @ojb.field primarykey=true * autoincrement=ojb */ private Integer pk=null; /** * user room * @ojb.reference *foreignkey=pk */ private Room room; } public class Room { /** * --- PK --- * @ojb.field primarykey=true * autoincrement=ojb */ private Integer pk=null; /** * Students in this room * @ojb.collection *foreignkey=fk *element-class-ref=kdms.core.persistent.User *auto-update=true *auto-retrieve=true *auto-delete=false */ private Vector users; } - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Crossreferenced Objects
I forgot to mention thaht I use OJB 1.0.1. On Tue, 25 Jan 2005 22:51:09 +0900, Sylvain ~ [EMAIL PROTECTED] wrote: I think the problems comes from the cache implementation I use, because It used to work quite well with jUnit tests and Default Cache Implementation, and in this situation there is only One thread so there wasn't any dirty read problem. However, since I moved the application in Struts Actions Under tomcat, I couldn't use the default Cache Implementation since it is not thread-safe, and I got some errors with retrieved data. So, I thought that using a thread-safe cache implementation such as ObjectCachePerBrokerImpl could solve the problem, and by doing so I solved the problems that used to happen, until I tried Crossreferenced Objects... I think that the source of the problem can be that I don't have any global cache, because I retrieve first the Room Object and the nested collection in a Struts Action (that might be running it it's own thread), and then on the users collection elements I try to get information on rooms, and it runs on a different thread from the first Action since it located in a different Action. So, I think that using a global cache which is thread-safe could solve this issue, however there is only few documentation on caches implementations in the cache package. As I read in the javadoc, it seems that ObjectCachePerClassImpl is a global cache, but i don't know if it thread-safe at all. I retrieve Objects using this code : public StorableObject get(Class objectClass, Integer pk) { PersistenceBroker broker = null; Object result; Criteria crit = new Criteria(); crit.addEqualTo(pk,pk); crit = criteraModificator(objectClass, crit); try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); QueryByCriteria query = new QueryByCriteria(objectClass, crit); result = broker.getObjectByQuery(query); } finally { if (broker != null) broker.close(); } return (StorableObject)result; } Regards, Sylvain. On Tue, 25 Jan 2005 11:23:02 +0100, Armin Waibel [EMAIL PROTECTED] wrote: Hi, which version of OJB do you use? Did you try the default ObjectCache implementation? Same result? How does your code look like? regards, Armin Sylvain ~ wrote: Hi, I'm trying to create crossreferenced objects, as specified in the Cache documentation : It allows to perform circular lookups (as by crossreferenced objects) that would result in non-terminating loops without such a cache. I Use ObjectCachePerBrokerImpl since my application is multi-threaded (and runs on tomcat) The problem is that I get a java.lang.StackOverflowError, when trying to do so with theses classes (simplified for clarity). both classes have auto-retrieve=true. Any Idea to make it work would be appreciated. Sylvain. public class User { /** * --- PK --- * @ojb.field primarykey=true * autoincrement=ojb */ private Integer pk=null; /** * user room * @ojb.reference *foreignkey=pk */ private Room room; } public class Room { /** * --- PK --- * @ojb.field primarykey=true * autoincrement=ojb */ private Integer pk=null; /** * Students in this room * @ojb.collection *foreignkey=fk *element-class-ref=kdms.core.persistent.User *auto-update=true *auto-retrieve=true *auto-delete=false */ private Vector users; } - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Crossreferenced Objects
I tried again to make it work all the day along, When I retrieve objects in Junit test cases, it doesn't give me any error with most of cache implementations... If anyone have any Idea, I am realy thinking this case is hopeless. Here is the full error stack : java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:296) at java.lang.Integer.toString(Integer.java:109) at java.lang.String.valueOf(String.java:2236) at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:558) at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:772) at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:944) at org.apache.ojb.broker.platforms.PlatformDefaultImpl.setObjectForStatement(PlatformDefaultImpl.java:249) at org.apache.ojb.broker.platforms.PlatformMySQLImpl.setObjectForStatement(PlatformMySQLImpl.java:87) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatementValue(StatementManager.java:216) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:248) at org.apache.ojb.broker.accesslayer.StatementManager.bindSelectionCriteria(StatementManager.java:424) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:388) at org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementManager.java:361) at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(JdbcAccessImpl.java:279) at org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(RsQueryObject.java:74) at org.apache.ojb.broker.accesslayer.RsIterator.init(RsIterator.java:183) at org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(RsIteratorFactoryImpl.java:58) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(PersistenceBrokerImpl.java:1808) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(PersistenceBrokerImpl.java:1333) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorByQuery(PersistenceBrokerImpl.java:1320) at org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(BasePrefetcher.java:104) at org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(QueryReferenceBroker.java:329) at org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(BasePrefetcher.java:113) at org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(QueryReferenceBroker.java:329) at org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(BasePrefetcher.java:113) at org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(QueryReferenceBroker.java:329) at org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(BasePrefetcher.java:113) (and so on...) On Wed, 26 Jan 2005 09:22:39 +0900, Sylvain ~ [EMAIL PROTECTED] wrote: I forgot to mention thaht I use OJB 1.0.1. On Tue, 25 Jan 2005 22:51:09 +0900, Sylvain ~ [EMAIL PROTECTED] wrote: I think the problems comes from the cache implementation I use, because It used to work quite well with jUnit tests and Default Cache Implementation, and in this situation there is only One thread so there wasn't any dirty read problem. However, since I moved the application in Struts Actions Under tomcat, I couldn't use the default Cache Implementation since it is not thread-safe, and I got some errors with retrieved data. So, I thought that using a thread-safe cache implementation such as ObjectCachePerBrokerImpl could solve the problem, and by doing so I solved the problems that used to happen, until I tried Crossreferenced Objects... I think that the source of the problem can be that I don't have any global cache, because I retrieve first the Room Object and the nested collection in a Struts Action (that might be running it it's own thread), and then on the users collection elements I try to get information on rooms, and it runs on a different thread from the first Action since it located in a different Action. So, I think that using a global cache which is thread-safe could solve this issue, however there is only few documentation on caches implementations in the cache package. As I read in the javadoc, it seems that ObjectCachePerClassImpl is a global cache, but i don't know if it thread-safe at all. I retrieve Objects using this code : public StorableObject get(Class objectClass, Integer pk) { PersistenceBroker broker = null; Object result; Criteria crit = new Criteria(); crit.addEqualTo(pk,pk); crit = criteraModificator(objectClass, crit); try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); QueryByCriteria query = new
XDoclet Bug with comments ?
Hi, Sorry if this have already been reported, but I think there is a bug in XDoclet with comments. When creating a persistent class, if there is any classic java comment between javadoc comments used to generate the class parameters in the repository and the class definition, the class is not included in the repository. Examples : It works with /** * @ojb.class table=users * */ public class User { ... } but it fails with /** * @ojb.class table=users * */ /* the bad comment that make your stuff not working */ public class User { ... } Sylvain. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: XDoclet Bug with comments ?
Yes, I understand, but in when designing and debugging an application it is sometimes convenient to disable some Xdoclets tags, and the quickest way to do it is to comment them with /**/ instead of /** */, so I find it logical, but sometimes confusing because it can make people waste a lot of time searching why their class is not in the repository. Sylvain. On Mon, 24 Jan 2005 10:57:10 +0100, Thomas Dudziak [EMAIL PROTECTED] wrote: I wouldn't say this is an XDoclet bug because as per Java Language Spec a comment starting with /** is only a documentation comment (i.e. a comment that is processed by Javadoc/XDoclet) if it comes directly before a class/method/field declaration (whitespace in between is allowed). So, in your example you cannot assume that the comment containing the @ojb.class tag will get processed by any comment-processing tool. Tom - 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]
Strange OJB Behaviour with Struts
I'm trying to create a web application with OJB Struts running on Tomcat. When I want to retrieve a set of Objects just after storing a new Object of the same type, this added Object is repeated many times at the end of the Collection. Example : if the records are : John, Carla, Greg I add Joe, so it becomes : John, Carla, Greg, Joe Then If now I add Vanessa I get this : John, Carla, Greg, Vanessa, Vanessa It does the same as long I add new objects, but Objects that were previously in the database like the three first are never altered. However, despite the retrieved data is wrong, the database data is right !!! If I try to reproduce the same scenario with jUnit test case, it doesn't create any error. I checked by logging access to data when retrieving it with PersistanceBroker to be sure it wasn't Struts in fault. I thought It was due to OJB cache, which is by default not Thread-safe, but after trying ObjectCacheDefaultImpl, ObjectCacheEmptyImpl and ObjectCachePerBrokerImpl I always get the same Error. Any Idea about the possible Source of the problem would be appreciated. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Re: Simple Inheritance problem with multiple class to one table mapping
Hi, Thank for your help, but I think I solved my problem. I don't know what I was doing wrong, but simply by rewriting by hand the Apartment Class, I solved the problem. Now I works really great, despite sometimes Eclipse seems to go a little crazy, so I think I also need to update it (ver 3.0.1). Thx, Sylvain. Sylvain Juge wrote: the XDoclet output is the following In fact now it doesn't process the Apartement.java file, and I don't know why because It used to process the file before. However, even if the file was processed by xdoclet, there was no result in the repository file, like now when it's not processed, that's why I found it weird. [ojbdoclet] Type kdms.core.Room [ojbdoclet] Type kdms.core.NetworkAddress [ojbdoclet] Type kdms.core.AbstractRoom [ojbdoclet] Processed 3 types [ojbdoclet] Processed 3 types Sylvain. I tried your classes and they worked without problems with a normal OJB 1.0.1 (I replaced the NetworkAddressVector with a List because I don't know about this class, and I added a dummy NetworkAddress as you didn't post it): --- package kdms.core; import java.util.List; /** * @ojb.class generate-table-info=false * @ojb.field name=abstractroom_id *primarykey=true *autoincrement=database *jdbc-type=INTEGER */ public class AbstractRoom { /** @ojb.field length=50 */ protected String ojbConcreteClass; /** @ojb.field name=number */ protected int number; /** @ojb.field name=size */ protected float size; /** * @ojb.collection name=nAddresses * element-class-ref=kdms.core.NetworkAddress * foreignkey=abstractroom_id * auto-update=true * auto-retrieve=true * auto-delete=false */ protected List nAddresses; } package kdms.core; /** * @ojb.class table=abstract_rooms * @ojb.field name=apartment_id *jdbc-type=INTEGER * @ojb.index name=room_unique *unique=true *fields=number,apartment_id */ public class Room extends AbstractRoom { /** @ojb.field name=capacity */ private int capacity; } package kdms.core; /** * @ojb.class table=abstract_rooms * @ojb.field name=testField *jdbc-type=INTEGER */ public class Apartment extends AbstractRoom {} package kdms.core; /** * @ojb.class table=network_address * @ojb.field name=abstractroom_id *primarykey=true *autoincrement=database *jdbc-type=INTEGER */ public class NetworkAddress {} --- [ojbdoclet] (XDocletMain.start 47 ) Running ojbrepository/ [ojbdoclet] Generating ojb repository descriptor (build/resources//repository_user.xml) [ojbdoclet] Type kdms.core.Room [ojbdoclet] Type kdms.core.NetworkAddress [ojbdoclet] Type kdms.core.AbstractRoom [ojbdoclet] Type kdms.core.Apartment [ojbdoclet] Processed 4 types [ojbdoclet] Processed 4 types [ojbdoclet] (XDocletMain.start 47 ) Running torqueschema/ [ojbdoclet] Generating torque schema (build/resources//project-schema.xml) [ojbdoclet] Processed 4 types --- !-- file containing the repository descriptions for user-defined types -- !-- Generated by the xdoclet-ojb module -- class-descriptor class=kdms.core.AbstractRoom extent-class class-ref=kdms.core.Apartment/ extent-class class-ref=kdms.core.Room/ /class-descriptor class-descriptor class=kdms.core.Apartment table=abstract_rooms field-descriptor name=abstractroom_id column=abstractroom_id jdbc-type=INTEGER primarykey=true autoincrement=true access=anonymous /field-descriptor field-descriptor name=ojbConcreteClass column=ojbConcreteClass jdbc-type=VARCHAR length=50 /field-descriptor field-descriptor name=number column=number jdbc-type=INTEGER /field-descriptor field-descriptor name=size column=size jdbc-type=REAL /field-descriptor field-descriptor name=testField column=testField jdbc-type=INTEGER access=anonymous /field-descriptor collection-descriptor name=nAddresses element-class-ref=kdms.core.NetworkAddress auto-retrieve=true auto-update=true auto-delete=false inverse-foreignkey field-ref=abstractroom_id/ /collection-descriptor /class-descriptor class-descriptor class=kdms.core.NetworkAddress table=network_address field
Simple Inheritance problem with multiple class to one table mapping
Hi, I'm quite newbie to OJB, and I really need help. I've got one base class AbstractRoom and two derived classes Room and Apartement, and I need to store them in one table named abstract_rooms. The problem is that when I generate repository schema for the database, it's like if the Apartement class is dropped (even if Xdoclet process the source file), because it is not present in the resulting repository file, thus absent of AbstractRoom extends. Despite abstract_rooms table contains all columns from Rooms class, there is no one from Apartement. It seems that my class Apartement is not seen by XDoclet as a persitence capable class, or simply forget my class and I wonder what Am I doing wrong. Any help would be appreciated. Sylvain. Relevant extract of Source files : --- Apartement.java --- /** * @ojb.class table=abstract_rooms * * @ojb.field name=testField * jdbc-type=INTEGER */ public class Apartment extends AbstractRoom { public Apartment(){ super(); ojbConcreteClass = Apartment.class.getName(); } public Apartment(Apartment apart){ super(apart); ojbConcreteClass = Apartment.class.getName(); } public Apartment(int number, float size){ super(number,size); ojbConcreteClass = Apartment.class.getName(); } --- AbstractRoom.java --- /** * @author Sylvain * 16:06:12 * @ojb.class generate-table-info=false * * -- doesn't seems to be taken in account event if I use determine-extends=false * @ojb.extent-class class-ref=kdms.core.Room * @ojb.extent-class class-ref=kdms.core.Apartement * * --- Primary Key --- * @ojb.field name=abstractroom_id * primarykey=true * autoincrement=database * jdbc-type=INTEGER **/ public class AbstractRoom implements StorableObject{ /** the special attribute telling OJB the object's concrete type. * NOTE: this attribute MUST be called ojbConcreteClass * @ojb.field length=50 */ protected String ojbConcreteClass; /** Room/Apt n° * @ojb.field name=number */ protected int number; /** Room/Apt size * @ojb.field name=size */ protected float size; /** * Network Addresses Collection * @ojb.collection name=nAddresses * element-class-ref=kdms.core.NetworkAddress * foreignkey=abstractroom_id * auto-update=true * auto-retrieve=true * auto-delete=false */ protected NetworkAddressVector nAddresses; } --- Room.java --- /** * @author Sylvain * 13:46:01 * * --- Class Storage Properties --- * * @ojb.class table=abstract_rooms * * * --- Foreign Keys --- * * @ojb.field name=apartment_id * jdbc-type=INTEGER * * --- Index --- * * @ojb.index name=room_unique *unique=true *fields=number,apartment_id */ public class Room extends AbstractRoom{ /** Student Capacity * @ojb.field name=capacity */ private int capacity; public Room(){ super(); ojbConcreteClass = Room.class.getName(); } public Room(int number, int capacity, float size){ super(number,size); ojbConcreteClass = Room.class.getName(); this.capacity = capacity; } public Room(Room r){ super(r); ojbConcreteClass = Room.class.getName(); this.capacity = r.capacity; } (...) } Sylvain Juge [EMAIL PROTECTED]
Re: Re: Simple Inheritance problem with multiple class to one table mapping
Here is the XDoclet schema output (repository_user.xml) I removed all irrelevant data to keep it clear. !-- file containing the repository descriptions for user-defined types -- !-- Generated by the xdoclet-ojb module -- class-descriptor class=kdms.core.AbstractRoom extent-class class-ref=kdms.core.Room/ /class-descriptor class-descriptor class=kdms.core.Room table=abstract_rooms field-descriptor name=abstractroom_id column=abstractroom_id jdbc-type=INTEGER primarykey=true autoincrement=true access=anonymous /field-descriptor field-descriptor name=ojbConcreteClass column=ojbConcreteClass jdbc-type=VARCHAR length=50 /field-descriptor field-descriptor name=number column=number jdbc-type=INTEGER /field-descriptor field-descriptor name=size column=size jdbc-type=REAL /field-descriptor field-descriptor name=apartment_id column=apartment_id jdbc-type=INTEGER access=anonymous /field-descriptor field-descriptor name=capacity column=capacity jdbc-type=INTEGER /field-descriptor index-descriptor name=room_unique unique=true index-column name=number/ index-column name=apartment_id/ /index-descriptor /class-descriptor Sylvain Juge wrote: Hi, I'm quite newbie to OJB, and I really need help. I've got one base class AbstractRoom and two derived classes Room and Apartement, and I need to store them in one table named abstract_rooms. The problem is that when I generate repository schema for the database, it's like if the Apartement class is dropped (even if Xdoclet process the source file), because it is not present in the resulting repository file, thus absent of AbstractRoom extends. Despite abstract_rooms table contains all columns from Rooms class, there is no one from Apartement. It seems that my class Apartement is not seen by XDoclet as a persitence capable class, or simply forget my class and I wonder what Am I doing wrong. Could you post the output of the XDoclet module ? Do you get any error/warning messages ? You can also try running Ant with the -v commandline option to get some more output. Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] .
Re: Re: Simple Inheritance problem with multiple class to one table mapping
the XDoclet output is the following In fact now it doesn't process the Apartement.java file, and I don't know why because It used to process the file before. However, even if the file was processed by xdoclet, there was no result in the repository file, like now when it's not processed, that's why I found it weird. [ojbdoclet] Type kdms.core.Room [ojbdoclet] Type kdms.core.NetworkAddress [ojbdoclet] Type kdms.core.AbstractRoom [ojbdoclet] Processed 3 types [ojbdoclet] Processed 3 types Sylvain. Sylvain Juge wrote: Here is the XDoclet schema output (repository_user.xml) I removed all irrelevant data to keep it clear. Ahem, I meant the console output when running Ant. The XDoclet module should write out all classes that it processes. Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] .
Inheritance problems
Hi, I'm quite newbie to OJB, and I really need help. I've got one base class AbstractRoom and two derived classes Room and Apartement, and I need to store them in one table named abstract_rooms. The problem is that when I generate repository schema for the database, it's like if the Apartement class is dropped (even if Xdoclet process the source file), because it is not present in the resulting repository file, thus absent of AbstractRoom extends. Despite abstract_rooms table contains all columns from Rooms class, there is no one from Apartement. It seems that my class Apartement is not seen by XDoclet as a persitence capable class, or simply forget my class and I wonder what Am I doing wrong. Any help would be appreciated. Sylvain. Relevant extract of Source files : --- Apartement.java --- /** * @ojb.class table=abstract_rooms * * @ojb.field name=testField * jdbc-type=INTEGER */ public class Apartment extends AbstractRoom { public Apartment(){ super(); ojbConcreteClass = Apartment.class.getName(); } public Apartment(Apartment apart){ super(apart); ojbConcreteClass = Apartment.class.getName(); } public Apartment(int number, float size){ super(number,size); ojbConcreteClass = Apartment.class.getName(); } --- AbstractRoom.java --- /** * @author Sylvain * 16:06:12 * @ojb.class generate-table-info=false * * -- doesn't seems to be taken in account event if I use determine-extends=false * @ojb.extent-class class-ref=kdms.core.Room * @ojb.extent-class class-ref=kdms.core.Apartement * * --- Primary Key --- * @ojb.field name=abstractroom_id * primarykey=true * autoincrement=database * jdbc-type=INTEGER **/ public class AbstractRoom implements StorableObject{ /** the special attribute telling OJB the object's concrete type. * NOTE: this attribute MUST be called ojbConcreteClass * @ojb.field length=50 */ protected String ojbConcreteClass; /** Room/Apt n° * @ojb.field name=number */ protected int number; /** Room/Apt size * @ojb.field name=size */ protected float size; /** * Network Addresses Collection * @ojb.collection name=nAddresses * element-class-ref=kdms.core.NetworkAddress * foreignkey=abstractroom_id * auto-update=true * auto-retrieve=true * auto-delete=false */ protected NetworkAddressVector nAddresses; } --- Room.java --- /** * @author Sylvain * 13:46:01 * * --- Class Storage Properties --- * * @ojb.class table=abstract_rooms * * * --- Foreign Keys --- * * @ojb.field name=apartment_id * jdbc-type=INTEGER * * --- Index --- * * @ojb.index name=room_unique *unique=true *fields=number,apartment_id */ public class Room extends AbstractRoom{ /** Student Capacity * @ojb.field name=capacity */ private int capacity; public Room(){ super(); ojbConcreteClass = Room.class.getName(); } public Room(int number, int capacity, float size){ super(number,size); ojbConcreteClass = Room.class.getName(); this.capacity = capacity; } public Room(Room r){ super(r); ojbConcreteClass = Room.class.getName(); this.capacity = r.capacity; } (...) } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weird things with anonymous attributes an Indexes
i'm quite a newbie using OJB, but I think that I found womething weird When using an index on two tables fields, it seems that if one of the two fields is an anonymous field, the index is simply forgiven on runtime. Here is the working example : [AbstractRoom.java] /** * * --- Artificial PK --- * * @ojb.field name=id * primarykey=true * autoincrement=database * jdbc-type=INTEGER */ abstract public class AbstractRoom implements StorableObject{ /** * Room/Apt n° * * @ojb.field name=number */ protected int number; ... } [Room.java] /** * @ojb.class table=kdms_rooms * * @ojb.index name=room_unique *unique=true *fields=number,apartment_id */ public class Room extends AbstractRoom { /** * Apt id (FK automatically managed by OJB) * @ojb.field name=apartment_id * jdbc-type=INTEGER * */ private int apartment_id; ... } -- And now the one that doesn't work --- [AbstractRoom.java] unchanged [Room.java] /* * @ojb.class table=kdms_rooms * * @ojb.index name=room_unique *unique=true *fields=number,apartment_id * * Apt id (FK automatically managed by OJB) * @ojb.field name=apartment_id * jdbc-type=INTEGER */ public class Room extends AbstractRoom { } This version results in an error in my JUnit test cases, because index seems to be ignored and duplicates are created when storing objects. However MySQL table index is the same in both cases, that's why I can't understand why is it possible to have such as duplicates... Any help would be appreciated. Sylvain. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: RE: Need Help !
Hi, It seems that when I load OJB, it doesn't automatically load the repository_database.xml file that is in the build/resources folder on runtime. I've seen that OJB is able to work like that, but I don't want to do it on runtime, just use static xml config files. Since i'm an absolute newbie, and I use Eclipse with defaults settings, is there anything special that I need to configure in order to make my program use the repository files ?? Any help will be appreciated, Thanks in advance. Sylvain. I always create the broker in this way: broker = PersistenceBrokerFactoryFactory.instance().defaultPersistenceBroker(); and I don't have problem, but I'm not an expert. -Mensaje original- De: Rajadurai K [mailto:[EMAIL PROTECTED] Enviado el: miércoles, 06 de octubre de 2004 11:58 Para: 'OJB Users List' Asunto: RE: Need Help ! hi, I think U have to increase the maxActive in Ojb.properties. can u do that and verify. Basically that error says that it can't able to get the connection from pool. Rajadurai -Original Message- From: Sylvain Juge [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 06, 2004 1:18 PM To: ojb-user Subject: Need Help ! I'm trying to use OJB API, and especially Object Persistance, but it doesn't work. I can build without any errors, the database schema is properly generated and executed on the RDBMS (MySQL). I've tried with default configuration files provided in ojb-blank, thus using embedded database, and I get exactly the same results. When I try to use PersistanceBroker, I've got two problems : -- I get an error because there's no default PBKey when I try to get the default Broker : broker = PersistenceBrokerFactory.defaultPersistenceBroker() results in : Exception in thread main org.apache.ojb.broker.PBFactoryException: There was no default-PBKey specified at org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.defaultPersi sten ceBroker(PersistenceBrokerFactoryBaseImpl.java:157) at org.apache.ojb.broker.PersistenceBrokerFactory.defaultPersistenceBroker( Pers istenceBrokerFactory.java:65) at PBSample.storeProduct(PBSample.java:19) at Application.run(Application.java:37) at Application.main(Application.java:28) -- When I try to use a specific PBKey created by hand : initially PersistenceBrokerFactory.getDefaultKey() returns null PBKey pbk = new PBKey(localmysql,root,); broker = PersistenceBrokerFactory.createPersistenceBroker(pbk); results in : Exception in thread main org.apache.ojb.broker.PBFactoryException: Borrow broker from pool failed, using PBKey org.apache.ojb.broker.PBKey: jcdAlias=localmysql, user=root, password=* at org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.createPer sist enceBroker(PersistenceBrokerFactoryDefaultImpl.java:119) at org.apache.ojb.broker.PersistenceBrokerFactory.createPersistenceBroker(P ersi stenceBrokerFactory.java:86) at PBSample.storeProduct(PBSample.java:25) at Application.run(Application.java:37) at Application.main(Application.java:28) Caused by: org.apache.ojb.broker.PBFactoryException: Given PBKey org.apache.ojb.broker.PBKey: jcdAlias=default, user=root, password=* does not match in metadata configuration at org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.createNewBro kerI nstance(PersistenceBrokerFactoryBaseImpl.java:87) at org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl$PBKeyedPo olab leObjectFactory.makeObject(PersistenceBrokerFactoryDefaultImpl.java:238) at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(Generic Keye dObjectPool.java:792) at org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.createPer sist enceBroker(PersistenceBrokerFactoryDefaultImpl.java:100) ... 4 more However, the repository_database.xml file (in build/ressources), seems to be well configurated, here is the file : jdbc-connection-descriptor jcd-alias=localmysql default-connection=true platform=MySQL jdbc-level=3.0 driver=com.mysql.jdbc.Driver protocol=jdbc subprotocol=mysql dbalias=//localhost/proj1 username=root password= batch-mode=false useAutoCommit=1 ignoreAutoCommitExceptions=false 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=0/ /object-cache connection-pool maxActive=21 validationQuery=@VALIDATION_QUERY@ testOnBorrow=@TEST_ON_BORROW@ testOnReturn=@TEST_ON_RETURN@ / sequence-manager className=org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImp l