Re: Introspection error in PersistentFieldPropertyImpl ?
Oh, man, did I screw up. PersistentFieldPropertyImpl *does* concern property names. It's PersistentFieldDefaultImpl that deals with the fields. Sorry. However, in your original message you seem to be using PersistentFieldPropertyImpl. This class uses the field and doesn't relate to the JavaBean spec. It's just going after field names without regard for JavaBean properties. So if you have a property "resembleValue" that uses a field called "", then in the repository.xml you'll need to refer to "", *NOT* "resembleValue". - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Introspection error in PersistentFieldPropertyImpl ?
Mario, It would be instructive for you to read the JavaBean spec at http://java.sun.com/products/javabeans/docs/spec.html Particularly section 8.2 Overview of Design Patterns. Here it describes the conventions concerning propery names and names of the setter/getter for a property. By those conventions, if your property is named "resembleValue" then the getter/setter methods are called "setResembleValue" and "getResembleValue". Also keep in mind, the property name has nothing to do with the field that the property may use to store it's value. The property "resembleValue" may use a field called "", or it may be more complicated and not have just one field. In any case, those are implementation details that are hidden by the getter/setter. However, in your original message you seem to be using PersistentFieldPropertyImpl. This class uses the field and doesn't relate to the JavaBean spec. It's just going after field names without regard for JavaBean properties. So if you have a property "resembleValue" that uses a field called "", then in the repository.xml you'll need to refer to "", *NOT* "resembleValue". Will Mario Toffia wrote: Tanks for the reply, First of all I'm not implying that it is a OJB bug since the Introspector is within the Sun's JDK but would the few lines be to harsh in performance and thus could not be integrated since I think that e.g. --> setresembleValue is not equally readable as (in code perspecive, not e.g ide managed environments) --> setResembleValue and thus gets more readable code. I won't challenge the java community with that and can accept such convention but I think latter method name for retrieving the property is far easer to read... I just thought it was method names started with non capital letter in the sentence e.g. removeAll, addTail and thus properties always begins with UC letter since getter and setter is prepended e.g. setMachineConfig, getId Many Regards, Mario -Original Message- From: Charles Anthony [mailto:[EMAIL PROTECTED] Sent: den 21 mars 2003 08:30 To: 'OJB Users List' Subject: RE: Introspection error in PersistentFieldPropertyImpl ? The Introspector and PropertyDescriptor are part of the JDK, not classes specific to OJB. I haven't got the JavaBean spec to hand, so I cannot categorically confirm that it is part of the JavaBean spec; however it is definitely a convention (widely adhered to) that the member variable of a property has a lower case first character. It is a little more complicated when both the the first letter and second letter are upper case - you'd have to read up on beans the Sun site. However, I can definitely confirm that this behaviour is not a bug. Cheers, Charles. -Original Message- From: Mario Toffia [mailto:[EMAIL PROTECTED] Sent: 21 March 2003 07:19 To: [EMAIL PROTECTED] Subject: Introspection error in PersistentFieldPropertyImpl ? Hi, I've got two methods (setter and getter) for a property in my bean that is called 'EquipmentId' (setEquipmentId, getEquipmentId) i.e. PersistentFieldPropertyImpl is used for Introspection. Using the repository.xml to map it like: " name="EquipmentId" column="EQNUM" jdbc-type="VARCHAR" indexed="true" nullable="false" /> " The code snippet in PersistentFieldPropertyImpl.findPropertyDescriptor(Class aClass, String aPropertyName) is doing the following. " info = Introspector.getBeanInfo(aClass); pd = info.getPropertyDescriptors(); for (int i = 0; i < pd.length; i++) { if (pd[i].getName().equals(aPropertyName)) { descriptor = pd[i]; break; } } " the getName returns the property of the bean but the first letter is Lower Case! is it by convension or is it a bug since setEquipmentId and getEquipmentId would yield a property named EquipmentId not equipmentId. The more stranger is when all letters in the setter and getter is UPPERCASE it would correctly return the property name i.e. if setEQUIPMENTID and getEQUIPMENTID is specified the p[i].getName() will return EQUIPMENTID! I've changed the code snippet to: " String csWritePropertyName = "set" + aPropertyName; for (int i = 0; i < pd.length; i++) { Method meth = pd[i].getWriteMethod(); if (null != meth) { if (true == meth.getName().equals(csWritePropertyName)) { descriptor = pd[i]; break; } } } if (pd[i].getName().equals(aPropertyName)) { descriptor = pd[i]; break; } " since Method.getName() correctly displays the method name (as always). I've never used the Introspector but I think this is a strange behaviour or? Many Regards, Mario - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email and any attachments are strictly confidential and are intended solely for the addressee. If you are not the intend
Re: Do I have to supply getXXX() and setXXX(...)-methods?
No you don't. Use the following setting in the OJB.properties file: PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDefaultImpl This assumes that your repository.xml mapping is based on fields in your classes. Henrik Berg wrote: Hi! Simple question: If I want to use OJB, do I have to make public set/get-methods for all the fields I want to store in the database? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What happens when an insert with ODMG fails?
Matthias, If an object has an ID that is set (not null or zero) then ODMG considers it to be an existing, persisted object that is already in the database. So locking it for write will result in an update, not an insert. In general, you shouldn't be setting the id. If you want an existing object then retrieve it with a query. If you want to create a new instance, then create it, set the business properties, and persist it. ODMG will assign an id and perform an insert. It's useful to at least think of your objects via a business interface that has business properties, but not any persistence related properties like the id and a timestamp. In this thinking, you can't set the id. This mindset gets you thinking more about the objects and less about the database. Regards, Will [EMAIL PROTECTED] wrote: Hi, following question about storing a new object: I have an Object with an attribute ID of type BigDecimal. I write the Object with ODMG: ... tx.lock(myObject, Transaction.WRITE); tx.commit(); if I set the ID to a valid number the every thing works fine. if I set the ID to a number witch still exists then no insert is made, but also not exception is thrown. Is there a way to find out if the insert was successful or not? regards Matthias Roth - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
m:n relation on tables I can't write to
I have an m:n relation with an implicit relation table, just like the Person/Project example. My twist, however, is that I don't have update rights to the Person and Project tables. I don't ever udate those tables anyway. They are institutional tables created an maintained by other processes. What I do need to update is the Person_Project table that holds the relation. I do have update rights to this table. Up until now in my development I haven't had to do any updates, so things have been fine. But now I need to update the relation table. I'm using ODMG so I do something like this: -- get the person -- get the project tx.lock(person, Transaction.WRITE); person.getProjects().add(project); tx.commit(); But this causes an update to the Person table which fails due to lack of privileges. Does anyone have suggestions for this situation? Perhaps with the PB api? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: cache confusion
Hi Armin, Here's some more details. I'm using OJB from CVS. I just updated today. I user ODMG api, but turn implicit locking off. Here's the behavior I see: I have a Faculty object with a proxied collection of Trainee objects. I have a web application, so let's say the user chooses a Trainee and clicks Delete. The action does the following, each in a separate ODMG transaction. - (the Faculty object has previously been retreived and put into the session.) - get the Trainee object using the OID, delete the trainee (both in one tx) - get the Faculty object using the OID I then put the Faculty into the sessions and use its trainee collection to populate a dropdown box of Trainees. What happens is that the deleted trainee continues to appear in the list. Via debugging I can see that the Faculties trainee collection still has the deleted trainee. It seems that the Faculty object is always gotten from the cache and never from the db, so the Trainee collection is wrong. I have to restart my application server in order for the correct collection to show. This make so sense to me. Clearly I'm not understanding the cache. Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cache confusion
I find that I'm just not understanding how the cache works, or the proper way to work with it. I use the ODMG api in a web application. I thought I had read here on the email list that the cache was used within a transaction but that it was cleared after the transaction ended. But I found that some of my dropdown boxes were not being updated because they were being pulled from the cache, eventhough they were being retreived within a separate transaction. This was unexpected. So I switched to using the ObjectCacheEmptyImpl until I understood caching better. But *even* *then* I found that objects were not always refreshed from the database. This was *totally* unexpected. I finally had to put a broker.clearCache() just after opening my transactions in order to guarantee that I actually pulled from the database. Clearly, I'm not doing or understanding something properly. I've read the cache html docs, but perhaps someone could talk about the cache and how to work with it successfully. Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
using ODMG as a singleton
Is it proper to use ODMG as a singleton in my web application? I have the following class (brief version) that gets the ODMG Implementation object once, and opens the database once. From then on I simply call OjbDAOFactory.getODMG(). Is this a safe and proper way to do things? If not, what would be a better usage? Thanks. public class OjbDAOFactory { static Implementation odmg; static Database db; static { try { odmg = OJB.getInstance(); db = odmg.newDatabase(); db.open("default", Database.OPEN_READ_WRITE); } catch (ODMGException ex) { LOGGER.error("", ex); } } public static Implementation getODMG() { return odmg; } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: using OJB with Struts and Eclipse
Another way to do it is to configure the WEB-INF/classes as a source directory (eventhough it is also the target directory) That way it doesn't get cleared. This works for me. Will [EMAIL PROTECTED] wrote: Philippe, Another solution is: create a new folder and put the conf files here configure this folder as a source folder when you build the project, your conf files will be automatically copied in WEB-INF/classes Regards Sylvain -Message d'origine- De: Christopher C Worley [mailto:[EMAIL PROTECTED] Date: mardi, 4. mars 2003 19:57 À: OJB Users List Objet: Re: using OJB with Struts and Eclipse Philippe, Change your eclipse build directory from /WEB-INF/classes to /classes. -chris worley Hello, I am currently building a web application based on Tomcat and Struts, using the Eclipse IDE. Trying to use OJB as the persistence layer, I have the following problem : The OJB spec. requires that the config files (OBJ.properties, repository.xml...) be retrieved from the classpath, which means, for a Tomcat application, in the WEB-INF/classes directory. But any files I manually put there are automatically removed by Eclipse if I rebuild the project, since this directory is an output folder for class compilation !! I've tried to work around this by creating another folder in my project (say "obj-config") and adding it to the classpath as a "lib" folder. But my application doesn't seem to be able to find repository info there (although it does if I run the same code as a Java application, i.e. without Tomcat). Can anyone help ? Thanks, Philippe - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: query formulation question
I have done more experimentation and found that my pseudo ODMG was actually quite close. The following ODMG query runs: select person from " + Person.class.getName() + " where roles.project.title != XXX" Unfortunately, this only returns persons that have at least one role. It doesn't return all the persons that have no roles. So I still don't quite know the answer to my original question. And this brings up another one: How would one formulate the query to return all persons that have no roles? As an incentive to get answers to these query formulation questions, I promise to write up a FAQ on what I learn. Will Phil Warrick wrote: Hi all, Does anyone have an answer for Will? I've often asked myself this same question. Or more generally how to deal with traversing towards the 'many' side of an association (1:m or n:m) in a query. Thanks, Phil Will Jaynes wrote: I'm wondering how to formulate a query. I'm sure this is s FAQ, but I can't find the answer... Looking at the "Mapping M:N associations" section of the "Advanced O/R" doc, I have a situation which is analogous to the Person, Project, PersonProject example of decomposition into two 1:N associations. I'd like to retrieve all Person objects that do not have a Project with title = "XXX". This seems kind of complicated since, if I were to write it in psuedo ODMG I would write select person from Person.class.getName() where roles[*].project.title != "XXX" How would this really be formulated in ODMG? How would this be formulated in just the PB? Thanks, Will - 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]
query formulation question
I'm wondering how to formulate a query. I'm sure this is s FAQ, but I can't find the answer... Looking at the "Mapping M:N associations" section of the "Advanced O/R" doc, I have a situation which is analogous to the Person, Project, PersonProject example of decomposition into two 1:N associations. I'd like to retrieve all Person objects that do not have a Project with title = "XXX". This seems kind of complicated since, if I were to write it in psuedo ODMG I would write select person from Person.class.getName() where roles[*].project.title != "XXX" How would this really be formulated in ODMG? How would this be formulated in just the PB? Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
collection proxies and ODMG, usefull?
It was my impression that the collection proxies would delay the loading of the objects in the collection until I actually tried to reference them. This does not seem to be true when using the ODMG api, as I am doing. I have an object graph with a lot of interconnections. Querying on one object has the potential to pull in alot of objects. So all of my collection-descriptors specify proxy="true". Regardless of this configuration, using the ODMG API, when I query on one object the rest of the object graph is also read in from the database. For each collection I see a "select count(..)" kind of query, and then a select to bring in the collection, and so on through out the object graph. My test looks just like the "retrieving collections" example in the ODMG tutorial. My query specified the oid for an object. I expected to get materialize just that one object. Am I missing something? I don't see how I can use the ODMG api if it is going to bring in the entire graph each time I need one object. Thanks, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: building from CVS, problems
Well... I found these three jars in the OJB/lib of an old OJB directory that I had hidden away. After including these jars compiling still failed. Then I copied two jboss jars from the old to the new OJB/lib. Now compiling gets farther, still fails in org.jboss.ojb.pb.PBFactory.java. So, just what all do I need for building OJB that isn't included in the CVS? Will Will Jaynes wrote: Today, I updated from the OJB CVS and found I couldn't compile, neither within Eclipse, which used to work, nor using just Ant. According to the Eclipse .classpath file in CVS there are three new jar files expected to be in the OJB/lib directory: servlet.jar ejb.jar jts-spec1_0_1.jar I have a servlet.jar file. Where do the others come from? Regards, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
building from CVS, problems
Today, I updated from the OJB CVS and found I couldn't compile, neither within Eclipse, which used to work, nor using just Ant. According to the Eclipse .classpath file in CVS there are three new jar files expected to be in the OJB/lib directory: servlet.jar ejb.jar jts-spec1_0_1.jar I have a servlet.jar file. Where do the others come from? Regards, Will - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: 0.9.9 vs. P6Spy vs. Tomcat
I've experienced this same problem when moving to 0.9.9. Actually I've seen it for some weeks, since I work from the CVS version. I use Resin rather than Tomcat, so it isn't restricted to one app server. As with Steve's experience, it stopped working when the only thing that had changed was upgrading OJB. Regards, Will Jaynes sclark wrote: Does anybody else have P6Spy working with 0.9.9 and Tomcat? I have had it working with 0.9.7 and 0.9.8, as well as with various intermediate bits from the CVS HEAD. But now that I've upgraded to 0.9.9, I don't get any output in my spy.log (actually, I get a bunch of startup messages in there, but no actual SQL logging). I have p6spy.jar in WEB-INF/lib and spy.properties in WEB-INF/classes. This has not changed for weeks, nor has my Tomcat setup. The only thing that has changed is ojb.jar. Any ideas? thanks, -steve Steve Clark Technology Applications Team Natural Resources Research Center/USGS [EMAIL PROTECTED] (970)226-9291 - 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: Can no longer connect to DB under 0.9.9
Robert, There is a change in the 0.9.9 version on how to refer to the database. Previously one would refer to repository.xml, now one needs to refer to the jcd-alias attribute, in your case "postgres". This is because one can now define multiple db connections. If you want your code to work as it currently is then change your connection descriptor to jcd-alias="repository.xml" Regards, Will Robert S. Sfeir wrote: This is most likely a newbie thing, but I've got my datasource setup properly, I've copied the latest files from the 0.9.9 and modified the repository_database.xml to have the following XML block: jcd-alias="postgres" default-connection="true" platform="PostgreSQL" jdbc-level="2.0" driver="org.postgresql.Driver" protocol="jdbc" subprotocol="postgresql" dbalias="//localhost:5432/rex" username="rex" password="" batch-mode="false"> But for some reason I get this (By the way there's a typo it should Could not find not Could not found). I know it can find the repository.xml since it found the datasource. Which user and password does it expect? The ojb jar file is in the lib directory for my webapp under WEB-INF... all this was working OK under 0.9.8. :-\ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]