RE: Synchronizing two databases with the same model
Jonas, I wonder if the OpenJPA Remote and Offline Operation stuff (http://openjpa.apache.org/docs/latest/manual/ref_guide_event.html) may allow you to build what you're after... Regards, Michael -Original Message- From: Andy Schlaikjer [mailto:[EMAIL PROTECTED] Sent: jeudi, 1. mai 2008 18:44 To: users@openjpa.apache.org Subject: Re: Synchronizing two databases with the same model Jonas, I'm glad you asked this question as I'd also been thinking about how I might get around restrictions the @GeneratedValue annotation enforces within OpenJPA. In certain circumstances I need to specify the value of a field marked with @GeneratedValue explicitly when persisting a new entity instance. I'd hoped that perhaps merge semantics would differ from persist semantics with respect to this constraint, but it seems (quite logically) that the constraint is applied uniformly to all entity life-cycle operations. For the time being I've had to fall back on JDBC to persist new data, but it'd be great if there were a way to signal to OpenJPA that a field marked with GeneratedValue may be explicitly defined for certain operations, like merge or persist. Andy Jonas Petersen wrote: Hi Brill, thanks for replying. The thing is, that only certain parts (e.g. an entity with certain id including child objects) have to get synchronized at the time by demand of a content editor. The datastore is mysql 5. Jonas Brill Pappin schrieb: Actually, the most obvious approach is not to write some special code, but simply enable replication and don't worry about trying to get OJPA to sync. What kind of database is it (most popular db's have replication of one sort or another)? - Brill Pappin -Original Message- From: Jonas Petersen [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 30, 2008 3:25 PM To: users@openjpa.apache.org Subject: Synchronizing two databases with the same model Hi there! We have one data model and we need two datastores with that same data model. Datastore A for editing and previewing and datastore B for production (live). Now we need to synchronize parts of datastore A to datastore B. The most obvious approach would be: fetch objects from datastore A (and possibly detach the objects) and then merge them in database B. But this rises a couple of problems due to versioning / sequence generators / optimistic locking / ... e.g.: - If objects (detached from datastore A) do not exist in datastore B, they are assumed deleted and an exception is thrown - Since we're using the GeneratedValue annotation for ids, objects would not be able to get persisted in datastore B even if they were new. Do you have any idea how to solve this problem in a regular way? One (non JPA-)way would be to implement it with native queries. Maybe this is the only way? Would probably be harder to maintain though. Thanks for any suggestion! Regards Jonas This email and any files transmitted with it are CONFIDENTIAL and intended solely for the use of the individual or entity to which they are addressed. Any unauthorized copying, disclosure, or distribution of the material within this email is strictly forbidden. Any views or opinions presented within this e-mail are solely those of the author and do not necessarily represent those of Odyssey Financial Technologies SA unless otherwise specifically stated. An electronic message is not binding on its sender. Any message referring to a binding engagement must be confirmed in writing and duly signed. If you have received this email in error, please notify the sender immediately and delete the original.
Jazoon conference, anybody?
Hello, Is anybody here may be attending the http://jazoon.com/ conference (in Zurich/Switzerland, in late June) ? I'll be there and it could be fun to meet-up with other OpenJPA folks from near or far. Regards, Michael _ Michael Vorburger, Odyssey Financial Technologies This email and any files transmitted with it are CONFIDENTIAL and intended solely for the use of the individual or entity to which they are addressed. Any unauthorized copying, disclosure, or distribution of the material within this email is strictly forbidden. Any views or opinions presented within this e-mail are solely those of the author and do not necessarily represent those of Odyssey Financial Technologies SA unless otherwise specifically stated. An electronic message is not binding on its sender. Any message referring to a binding engagement must be confirmed in writing and duly signed. If you have received this email in error, please notify the sender immediately and delete the original.
RE: List mapping of Enumerated Types
Amit, I imagine I do not need a join table, but a child table that has the owner entity ID, Enumerated String Value and a Sequence, but I do not know how to represent that in a @OneToMany annotation. This looks a bit like my Re: One-Sided One-Many Mapping, but to different tables - missing @ElementEmbeddedMapping ? thread (monologue, almost). With the latest trunk and upcoming 1.1 version of OpenJPA you can use @ContainerTable instead of @OneToMany it seems for this kind of mapping. However, I have no idea if that would work, or is even needed, for a Collection/List of enum. Regards, Michael -Original Message- From: Patel Amit [mailto:[EMAIL PROTECTED] Sent: vendredi, 2. mai 2008 23:44 To: users@openjpa.apache.org Subject: List mapping of Enumerated Types Hello Jpa Community, I have a question on how to annotate a Collection of enums in my Entity. I have an Entity which has a List of Enums: private ListKeyUsuage keyUsuage = new ArrayListKeyUsuage(); Where KeyUsuage is the following enum: public enum KeyUsuage { digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, CRLSign, encipherOnly, decipherOnly, AllExtendedKeyUsage; } How do I go about mapping this to a table. I imagine I do not need a join table, but a child table that has the owner entity ID, Enumerated String Value and a Sequence, but I do not know how to represent that in a @OneToMany annotation. Has anyone done this before or know how to do it? Is this possible in JPA? Thanks for the help. Amit This email and any files transmitted with it are CONFIDENTIAL and intended solely for the use of the individual or entity to which they are addressed. Any unauthorized copying, disclosure, or distribution of the material within this email is strictly forbidden. Any views or opinions presented within this e-mail are solely those of the author and do not necessarily represent those of Odyssey Financial Technologies SA unless otherwise specifically stated. An electronic message is not binding on its sender. Any message referring to a binding engagement must be confirmed in writing and duly signed. If you have received this email in error, please notify the sender immediately and delete the original.
Re: Synchronizing two databases with the same model
Hi Michael, thank you for the response! I'm afraid that this won't help much. It's about notification. If I get notified I still have to synchronize. Further it allows a subset of the information available through OpenJPA's transaction events to be broadcast to remote listeners. And ...that will be alerted with a list of modified object ids whenever a transaction on a remote machine successfully commits. So it's tied to a transaction? What we need is to synchronize a certain state of the db (or part of it). And that could be the essence of many transactions. Regards Jonas Michael Vorburger schrieb: Jonas, I wonder if the OpenJPA Remote and Offline Operation stuff (http://openjpa.apache.org/docs/latest/manual/ref_guide_event.html) may allow you to build what you're after... Regards, Michael
Re: List mapping of Enumerated Types
Hibernate JPA does this well with a custom annotation @CollectionOfElements Maybe something similar can be done for OpenJPA. - Brill Pappin On Tue, May 6, 2008 at 5:10 AM, Michael Vorburger [EMAIL PROTECTED] wrote: Amit, I imagine I do not need a join table, but a child table that has the owner entity ID, Enumerated String Value and a Sequence, but I do not know how to represent that in a @OneToMany annotation. This looks a bit like my Re: One-Sided One-Many Mapping, but to different tables - missing @ElementEmbeddedMapping ? thread (monologue, almost). With the latest trunk and upcoming 1.1 version of OpenJPA you can use @ContainerTable instead of @OneToMany it seems for this kind of mapping. However, I have no idea if that would work, or is even needed, for a Collection/List of enum. Regards, Michael -Original Message- From: Patel Amit [mailto:[EMAIL PROTECTED] Sent: vendredi, 2. mai 2008 23:44 To: users@openjpa.apache.org Subject: List mapping of Enumerated Types Hello Jpa Community, I have a question on how to annotate a Collection of enums in my Entity. I have an Entity which has a List of Enums: private ListKeyUsuage keyUsuage = new ArrayListKeyUsuage(); Where KeyUsuage is the following enum: public enum KeyUsuage { digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, CRLSign, encipherOnly, decipherOnly, AllExtendedKeyUsage; } How do I go about mapping this to a table. I imagine I do not need a join table, but a child table that has the owner entity ID, Enumerated String Value and a Sequence, but I do not know how to represent that in a @OneToMany annotation. Has anyone done this before or know how to do it? Is this possible in JPA? Thanks for the help. Amit • This email and any files transmitted with it are CONFIDENTIAL and intended solely for the use of the individual or entity to which they are addressed. • Any unauthorized copying, disclosure, or distribution of the material within this email is strictly forbidden. • Any views or opinions presented within this e-mail are solely those of the author and do not necessarily represent those of Odyssey Financial Technologies SA unless otherwise specifically stated. • An electronic message is not binding on its sender. Any message referring to a binding engagement must be confirmed in writing and duly signed. • If you have received this email in error, please notify the sender immediately and delete the original.
Re: Getting the persistence unit name from an EntityManagerFactory
Hi Roger, If you are able to use the OpenJPA interfaces directly (as opposed to purely using the implementation agnostic JPA interfaces) you can use the OpenJPA SPI to get the pu name from the emf. Here is some sample code: EntityManagerFactory emf = Persistence.createEntityManagerFactory(MyPU); if (emf instanceof org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI) { org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI ojemf = (org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI) emf; org.apache.openjpa.conf.OpenJPAConfiguration ojc = ojemf.getConfiguration(); System.out.println(pu name: + ojc.getId()); } The doc for the getId method indicates that it may return the PU name or some other more-unique value for the current environment. A quick scan showed that the id should == the pu name unless you are in a distributed db/slice environment. (I could have missed something though) If you need to find the pu name from an em you can get the OpenJPA emf with this code: EntityManager em = emf.createEntityManager(); org.apache.openjpa.persistence.OpenJPAEntityManager ojem = (org.apache.openjpa.persistence.OpenJPAEntityManager)em; org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI ojemf = (org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI)ojem.getEntityManagerFactory(); -Jeremy On 5/4/08, roger.keays [EMAIL PROTECTED] wrote: Does OpenJPA have any tricks we could use to get the persistence unit name which was used to create an EntityManager{Factory}? Cheers, Roger -- View this message in context: http://www.nabble.com/Getting-the-persistence-unit-name-from-an-EntityManagerFactory-tp17044912p17044912.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
Reverse mapping with many/many association
I'm trying to generate annotated classes using a database using the reverse-mapper included with OpenJPA. I have two tables, a and b, that are paired using a many to many association table in between (a_b_junction). Is it possible, using the reverse-mapper task, to customize the generated classes so that class a contains a reference to a list of b objects instead of the association itself? Furthermore, can I achieve this using a wildcard in the customizer.properties file? Thanks - James