object initilisation question ?
Hello, First i would like to thank all the OJB developers, i'am using it to develop an opensource picture management web application that i hope will be usable one day, i really don't get why OJB is almost never mentioned in talks about object persistencers but i hope it will change one day. It kind of scares me to see that everyone uses Hibernate, i hope OJB will catch up in terms of audience. I'am getting trouble retrieving an instance of a class representing a tree structure with ojb (last release), in the database the record is good : parentidid namedescription hJ}Tfk7o>#S[Om?\AP:X}T1yhJ}Tfk7o>#S[Om?\AP:X}T1yterre hJ}Tfk7o>#S[Om?\AP:X}T1yOK?`L_igc>JlU:m66mH^",@:france OK?`L_igc>JlU:m66mH^",@:(ZjHVf">aQvtj%6H)$NC$7hlparis (ZjHVf">aQvtj%6H)$NC$7hl)f[u|G'za6-&!P]OUlp-=z>ntoureiffel (ZjHVf">aQvtj%6H)$NC$7hlWz:YyW,[EMAIL PROTECTED];Abnf Wz:YyW,[EMAIL PROTECTED];ABWZ[_/i>Oq{Kj48VXBPOe.~&salle1 So OJB was able to persists it right. But whem i'am trying to retrieve the structure, it's kind of messed up, as "terre" wich is the root of the tree is the child of itself, like that : terre terre france .. I don't know what i'am doing bad, but i tried to secure my getter and setters so it's not possible to add a child which is the same object. I was surprised to not get an exception, so i tried to add breakpoints to all my getters and setters to see when OJB is calling them, but it never stop at my breakpoints. So how does OJB set the attributes of the instances (my instances attributes are private) ? i really don't get it. Thank you. Jean-Yves Here is the code of my class if someone can understand the problem : /* * Created on 6 déc. 2004 * */ package org.jys.jphotowiki.data.locate; import java.io.Serializable; import java.util.List; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jys.jphotowiki.data.DataIntegrityException; import org.jys.jphotowiki.data.IDataObject; import org.jys.jphotowiki.test.pers.TestBaseCreation; /** * Class representing some location, has a parent and some childs of same type * to make a tree of locations. Location with itself has parent is the root * location (ancestor of all other locations within the context of an * [EMAIL PROTECTED] org.jys.jphotowiki.data.DocumentBase}, a location with no child is a * leaf of the location tree. * * @ojb.class * @ojb.field name="parentId" jdbc-type="VARCHAR" nullable="false" * @author jysu_cb */ public class Location implements IDataObject, Serializable { protected Log _log = LogFactory.getLog(Location.class); /** * Comment for serialVersionUID */ private static final long serialVersionUID = 6009335074727417445L; /** * internal id * * @ojb.field primarykey="true" */ private String id; /** * name * * @ojb.field */ private String name; /** * description * * @ojb.field length="200" */ private String description; /** * parent location * * @ojb.reference foreignkey="parentId" auto-update="none" *auto-delete="none" */ private Location parent; /** * @ojb.collection element-class-ref="org.jys.jphotowiki.data.locate.Location" * foreignkey="parentId" */ private List childs = new Vector(); public void addChild(Location newChild) { if (!newChild.isNew()) { throw new IllegalArgumentException("Can only insert a new Location"); } childs.add(newChild); newChild.setParent(this); } public int size() { int result = 1; for (Location child : getChilds()) { result += child.size(); } return result; } /** * @return Returns the childs. */ public List getChilds() { return childs; } /** * @param childs *The childs to set. */ public void setChilds(List childs) { _log.debug("Setting childs : " + childs); if (childs.contains(this)) { throw new IllegalArgumentException("One of my son is myself"); } this.childs = childs; } /** * @return Returns the id. */ public String getId() { return id; } /** * @param id *The id to set. */ public void setId(String id) { this.id = id; } /** * @return Returns the description. */ public String getDescription() { return description; } /** * @param description *The description to set. */ public void setDescription(String description) { this.description = description; } /** * @return Returns the name. */ public Strin
Re: Oracle9i and sequences
Hi, > Now that I've found what the problem was, I'd like to make a little > suggestion improvement on the PlatformOracleImpl class: Could it be > possible that the method: > > public String createSequenceQuery(String sequenceName) > > takes into account the index start sequence hints we pass in the > sequence manager definition? That'd be great! > I think this will be possible, but this requires changes in method Platform#createSequenceQuery(String sequenceName), please make a feature request in jira http://issues.apache.org/jira/secure/BrowseProject.jspa?id=10700 > drop/recreate them, that was just fine. So I used some sequence > creation like so: > > CREATE SEQUENCE FOOBAR_SEQ START WITH 41 MAXVALUE > 999 MINVALUE 1 NOCYCLE CACHE 20 NOORDER; Is it possible in Oracle only to specify the start index without the other settings? E.g. CREATE SEQUENCE FOOBAR_SEQ START WITH 41 If yes, please add this example in feature request too. regards, Armin Guillaume Laforge wrote: First of all, thanks to both Thomas :-) On 03/08/05, Thomas Franke <[EMAIL PROTECTED]> wrote: Thomas Dudziak wrote: * Leave the pk generation to the database. In that case, use the native sequence manager. With Oracle it would be a problem I think. If I right the native sequence manager don't work with Oracle. Therefore we use SequenceManagerNextValImpl and leave the pk generation to Oracle. I can confirm that the native sequence manager doesn't work with Oracle. That's the first solution I tried, but I couldn't make it work. Now, back to my problem... Well, I think I've managed to make things work as I expected. But the overall problem was slightly more complex. Here are some more explanations and details: I had a base class with the ID / xDoclet field definition that all my persistent classes were extending. It worked fine with OJB's HiLo, but with *NextValImpl, that wasn't great, especially with autonaming="true". So in order to define my sequences' names at hand, I had to define my ID field in all my persistent classes. I didn't want a single sequence for all my tables. But that's not all... I still couldn't insert my objects in the database because some constraints were violated... and they were, because the *NextValImpl starts inserting values with ID starting at 1! And the globalSequenceStart attribute in the sequence manager definition isn't taken into account. So I can't specify the index at which I want to start. What a pity! The solution to that problem was that I created the sequences manually after I insert my first init data set, and since OJB doesn't drop/recreate them, that was just fine. So I used some sequence creation like so: CREATE SEQUENCE FOOBAR_SEQ START WITH 41 MAXVALUE 999 MINVALUE 1 NOCYCLE CACHE 20 NOORDER; And now, it seems everything is working as expected :-) So thank you Thomas and Thomas for your help! Now that I've found what the problem was, I'd like to make a little suggestion improvement on the PlatformOracleImpl class: Could it be possible that the method: public String createSequenceQuery(String sequenceName) takes into account the index start sequence hints we pass in the sequence manager definition? That'd be great! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: PB and Oracle9i: transaction issue
Hi, if you set "useAutoCommit=1", OJB set the connection autoCommit attribute to 'false' when PB-tx demarcation is used. After the PB-tx the autoCommit attribute is reset to 'true'. http://db.apache.org/ojb/docu/guides/repository.html#useAutoCommit Everything done between PB.begin... and PB.commit... will use the same connection with autoCommit 'false', thus on rollback nothing will be written to DB. regards, Armin Guillaume Laforge wrote: Hi all, I'm having some issues with the PersistenceBroker. I've got a one-to-many relationship, say a sentence, which has got localized labels (1 sentence <-> several multilingual labels). I want to store a new sentence with a new set of labels. But I want to do that in a single transaction, so that if something fails, I can rollback everything. So, somewhere in my code, I'm doing a broker.beginTransaction(). I store my sentence. I create some labels a bit further and store them. And later, broker.commitTransaction(). And in case something fails, I'm rollback-ing the transaction in some try catch finally surrounding my code. If autocommit is true, then my sentences and labels are stored... but, unfortunately, if something goes wrong, OJB won't rollback anything. So autocommit to true is not a good option for me since I want a real transaction (I also tried setting autocommit on the broker object itself but that wasn't any better). If I set useAutoCommit="2" in my jdbc-connection-descriptor, I store my sentence, but just after I see a weird message in the logs: accesslayer.ConnectionManagerImpl - Release connection: connection is in local transaction, missing 'localCommit' or 'localRollback' call - try to rollback the connection And then, when I try to store the first label, I get an exception: org.apache.ojb.broker.KeyConstraintViolatedException: SQL failure while insert object data for class com.foo.bar.Xxxx, PK of the given object is [ id=201], object was , exception message is [ORA-02291: integrity constraint (AE6.SYS_C001821) violated - parent key not found. The message basically means that it can't find the sentence primary key that the label is referencing (foreign key). Background: I'm using OJB 1.0.3 and Oracle 9i with the thin driver. So, I was wondering how I could store a new sentence and label in on transaction and be able to rollback everything if I so desire? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
PB and Oracle9i: transaction issue
Hi all, I'm having some issues with the PersistenceBroker. I've got a one-to-many relationship, say a sentence, which has got localized labels (1 sentence <-> several multilingual labels). I want to store a new sentence with a new set of labels. But I want to do that in a single transaction, so that if something fails, I can rollback everything. So, somewhere in my code, I'm doing a broker.beginTransaction(). I store my sentence. I create some labels a bit further and store them. And later, broker.commitTransaction(). And in case something fails, I'm rollback-ing the transaction in some try catch finally surrounding my code. If autocommit is true, then my sentences and labels are stored... but, unfortunately, if something goes wrong, OJB won't rollback anything. So autocommit to true is not a good option for me since I want a real transaction (I also tried setting autocommit on the broker object itself but that wasn't any better). If I set useAutoCommit="2" in my jdbc-connection-descriptor, I store my sentence, but just after I see a weird message in the logs: accesslayer.ConnectionManagerImpl - Release connection: connection is in local transaction, missing 'localCommit' or 'localRollback' call - try to rollback the connection And then, when I try to store the first label, I get an exception: org.apache.ojb.broker.KeyConstraintViolatedException: SQL failure while insert object data for class com.foo.bar.Xxxx, PK of the given object is [ id=201], object was , exception message is [ORA-02291: integrity constraint (AE6.SYS_C001821) violated - parent key not found. The message basically means that it can't find the sentence primary key that the label is referencing (foreign key). Background: I'm using OJB 1.0.3 and Oracle 9i with the thin driver. So, I was wondering how I could store a new sentence and label in on transaction and be able to rollback everything if I so desire? -- Guillaume Laforge http://glaforge.free.fr/blog/java - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Which ConnectionFactory?
I found the solution: The configuration of BasicDataSourceFactory in for the JNDI-DataSource was wrong. I had the value minIdle =0. In this case no connection will be pooled... > -Original Message- > From: Ribi Roland [mailto:[EMAIL PROTECTED] > Sent: Friday, August 05, 2005 2:12 PM > To: 'ojb-user@db.apache.org' > Subject: Which ConnectionFactory? > > > Hi > > I user OJB in Tomcat 5.0.28, the DB-Connections are declared as > JNDI-Data-Source in Tomcat (with BasicDataSourceFactory from > commons-dbcp). > > Which ConnectionFactory should I use? > > When I use DBCP-ConnectionFactory it establishes for every PB a new > connection, the same with PooledImpl. > > Any hints? > > Roland Ribi > > > - > 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]
Which ConnectionFactory?
Hi I user OJB in Tomcat 5.0.28, the DB-Connections are declared as JNDI-Data-Source in Tomcat (with BasicDataSourceFactory from commons-dbcp). Which ConnectionFactory should I use? When I use DBCP-ConnectionFactory it establishes for every PB a new connection, the same with PooledImpl. Any hints? Roland Ribi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]