It's a thorny problem. Have you looked at openjpa-slice<http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_slice>? Having a separate slice for each schema sounds like it would work for you. I haven't tried anything like what you want to do, but you should be able to set a different schema on each slice. Failing that you might be able to use different users and pick up a different default schema that way.
-mike On Fri, Aug 12, 2011 at 4:54 AM, Marcel Urbanek <dt0...@retail-sc.com>wrote: > Hi, > > thanks for your answer. > > We need to specify differing qualifier/schemas for the entities. > > So lets say Entity A is in Qualifier 'test1' and Entity B is in Qualifier > 'test2'. > Furthermore, depending on the platform the program is run, the Qualifier > may change. On Production Platform the Qualifier might be 'prod1' and > 'prod2' instead of 'test1' and 'test2'. And last but not least it should > also be possible to do joins between the two entities, while being in > differnet schemas/qualifiers. > > Following options do not work for us: > > - Specify the schema at the annotation (because the schema name changes > from platform to platform) > - Implementing an own OpenJPAEntityManagerFactory that set the schema for > the according persistence unit (because joins between the two persistence > units would not be possible) > > The idea was to implement a MetaDataFactory that returns a custom > MetaDataParser that itself handles the schemas in the > handleUnknownClassAnnotation() Method (via a custom @Qualifier annotation) > and manipulates the MetaData accordingly. > > Best regards Marcel > > > > From: Michael Dick <michael.d.d...@gmail.com> > To: users@openjpa.apache.org > Date: 11.08.2011 21:57 > Subject: Re: Problems when using "openjpa.MetaDataFactory" Property > > > > Hi again, > > I did a little digging and I have a couple of ideas on how to fix the > problem. Can you tell me what you want to do with your extension to the > MappingFactory? There might be another way to get what you need to do > done. > Or at least a different workaround that you can use while we work on a > fix. > > -mike > > On Thu, Aug 11, 2011 at 2:19 PM, Michael Dick > <michael.d.d...@gmail.com>wrote: > > > Hi Marcel, > > > > Thanks for sending the embeddable PK, I was missing that part. > > > > I see everything work if I set the MappingFactory plugin to the default > > value (org.apache.openjpa...) or leave the property blank. When I use a > > custom mapping factory I get the error where the column names aren't > picked > > up (bad SQL is generated). > > > > For some reason when you've specified your own MappingFactory OpenJPA > > forces the factory into strict mode and the column names are not > processed. > > It's fairly easy to change the code to not do that, but I'm not sure > what > > else I'd break. > > > > I haven't found a workaround for you yet, but at least I can reproduce > the > > problem. > > > > -mike > > > > > > On Thu, Aug 11, 2011 at 10:18 AM, Marcel Urbanek > <dt0...@retail-sc.com>wrote: > > > >> Hi, > >> > >> please note that my example/junit test works fine as long as I don't > >> change the Mapping Factory properties. Only when changing the > >> MappingFactory it goes wrong. > >> > >> My Group Entity looks like this: > >> > >> > >> @Embeddable > >> public class GroupPK { > >> /*Group Number*/ > >> @Column(name = "NU_GRP", > >> length=2) > >> private Short groupNumber; > >> > >> /*Group name*/ > >> @Column(name = "NA_GRP", > >> length=20) > >> private String groupName; > >> > >> /*Valid from*/ > >> @Temporal(TemporalType.DATE) > >> @Column(name = "DA_VAL_FRM", > >> length=4) > >> private Date validFromDate; > >> ... > >> > >> > >> @Entity > >> @Table(name="MPTZZY") > >> public class Group extends UpdateEntity{ > >> > >> /*Remark text*/ > >> @Column(name = "TE_RMK", > >> length=20) > >> private String remarkText; > >> > >> @OneToMany(mappedBy="group",fetch=FetchType.EAGER > >> ,cascade=CascadeType.ALL) > >> Collection<Person> persons=new ArrayList<Person>(); > >> > >> @EmbeddedId > >> private GroupPK id = new GroupPK(); > >> ... > >> > >> > >> > >> Best regards Marcel > >> > >> > >> > >> > >> > >> From: Michael Dick <michael.d.d...@gmail.com> > >> To: users@openjpa.apache.org > >> Date: 11.08.2011 16:36 > >> Subject: Re: Problems when using "openjpa.MetaDataFactory" > Property > >> > >> > >> > >> Going back to your original email, the documentation is misleading. > While > >> you could use PersistenceMetaDataFactory you'd probably prefer to use > >> PersistenceMappingFactory. Basically, you did the right thing by > extending > >> the PersistenceMappingFactory.. > >> > >> The product derivations are confusing, because they set the same alias. > >> But > >> they should always be applied in a consistent order. There's some > tricky > >> ordering in the code, but basically the PersistenceProductDerivation > >> should > >> always be called before JDBCPersistenceProductDerivation. > >> > >> If all you want to do is override the MetaDataFactory you do not need > to > >> write your own product derivation. ProductDerivations are needed if you > >> want > >> to support a different type of data store (maybe a non-relational > >> database), > >> or a different spec (JDO). I don't see a reason why you'd need to go > that > >> far. > >> > >> All that said, I think we're going to need to know more about your > model > >> to > >> figure out what is going wrong here. In particular what annotations are > on > >> the NA_GRP column. > >> > >> Once we get this to work with the OpenJPA defaults, we can look at what > >> goes > >> wrong with your MappingFactory. > >> > >> HTH > >> -mike > >> > >> On Thu, Aug 11, 2011 at 2:32 AM, Marcel Urbanek > >> <dt0...@retail-sc.com>wrote: > >> > >> > Hi Rick, > >> > > >> > when I use > >> > > >> > <property name="openjpa.MetaDataFactory" value=" > >> > > >> > > >> > >> > > "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory(types=com.retail_sc.test.entity.Group;com.retail_sc.test.entity.Person;)" > >> > /> > >> > > >> > The same error ("no registered metadata") occurs. > >> > > >> > After some investigation (looking at > JDBCPersistenceProductDerivation) I > >> > found out that following configuration: > >> > > >> > <property name="openjpa.MetaDataFactory" value= > >> > "org.apache.openjpa.persistence.PersistenceMetaDataFactory"/> > >> > <property name="openjpa.jdbc.MappingFactory" value= > >> > "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory"/> > >> > <property name="openjpa.jdbc.MappingDefaults" value= > >> > "org.apache.openjpa.persistence.jdbc.PersistenceMappingDefaults"/> > >> > > >> > Leads to following Exception: > >> > > >> > org.apache.openjpa.persistence.ArgumentException: You cannot > join > >> > on column "MPTZZY.NA_GRP". It is not managed by a mapping that > supports > >> > joins. > >> > > >> > which looks a little better to me? > >> > > >> > Actually I think the main problem is, that > PersistenceProductDerivation > >> > and JDBCPersistenceProductDerivation both are setting the "JPA" > Alias. > >> > > >> > But one sets MetaDataFactory for Alias JPA whith > >> > PersistenceMetaDataFactory and one sets MetaDataFactory for Alias JPA > >> with > >> > PersistenceMappingFactory. During execution both, > >> > PersistenceProductDerivation and JDBCPersistenceProductDerivation are > >> > invoked which results in MetaDataFactory being set to the one or the > >> other > >> > value, depending on which Derivation was called lately. This is > nothing > >> > one could easily configure in the persistence.xml. > >> > > >> > Instead I would have to implement an own Derivation? I am a little > >> > confused. > >> > > >> > Best regards Marcel > >> > > >> > > >> > > >> > > >> > From: Rick Curtis <curti...@gmail.com> > >> > To: users@openjpa.apache.org > >> > Date: 10.08.2011 18:31 > >> > Subject: Re: Problems when using "openjpa.MetaDataFactory" > >> Property > >> > > >> > > >> > > >> > Try specifying your types also --> <property > >> > name="openjpa.MetaDataFactory" > >> > > >> > > >> > >> > > value="org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory(types=com.retail_sc.test.entity.Group;com.retail_sc.test.entity.Group2;...etc/> > >> > > >> > This happens at runtime, but I can't find where it happens atm. > >> > > >> > On Wed, Aug 10, 2011 at 11:12 AM, Marcel Urbanek > >> > <dt0...@retail-sc.com>wrote: > >> > > >> > > Then following Stacktrace is displayed: > >> > > > >> > > Caused by: <openjpa-1.2.1-r752877:753278 fatal user error> > >> > > org.apache.openjpa.persistence.ArgumentException: Errors > encountered > >> > while > >> > > resolving metadata. See nested exceptions for details. > >> > > at > >> > > > >> > > > >> > > >> > > >> > >> > > org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:563) > >> > > at > >> > > > >> > > > >> > > >> > > >> > >> > > org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:308) > >> > > ... > >> > > Caused by: java.lang.IllegalStateException: No registered metadata > for > >> > > type "class com.retail_sc.test.entity.Group". > >> > > at > >> > > org.apache.openjpa.enhance.PCRegistry.getMeta(PCRegistry.java:255) > >> > > at > >> > > > org.apache.openjpa.enhance.PCRegistry.newInstance(PCRegistry.java:111) > >> > > ... > >> > > > >> > > Best regards Marcel > >> > > > >> > > > >> > > > >> > > From: Rick Curtis <curti...@gmail.com> > >> > > To: users@openjpa.apache.org > >> > > Date: 10.08.2011 18:04 > >> > > Subject: Re: Problems when using "openjpa.MetaDataFactory" > >> > Property > >> > > > >> > > > >> > > > >> > > See if setting this property works for you. --> <property > >> > > name="openjpa.MetaDataFactory" > >> > > > value="org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory/> > >> > > > >> > > Thanks, > >> > > Rick > >> > > > >> > > > >> > > On Wed, Aug 10, 2011 at 10:48 AM, Marcel Urbanek > >> > > <dt0...@retail-sc.com>wrote: > >> > > > >> > > > Sure. > >> > > > > >> > > > My Entity looks like the following: > >> > > > > >> > > > @Entity > >> > > > @Table(name="MPTZZY") > >> > > > public class Group extends UpdateEntity{ > >> > > > > >> > > > /*Remark text*/ > >> > > > @Column(name = "TE_RMK", > >> > > > length=20) > >> > > > private String remarkText; > >> > > > [...] > >> > > > > >> > > > > >> > > > The according Junit Test is the following (EJB-Services are > >> > implemented > >> > > > straight forward): > >> > > > > >> > > > GroupServiceLocal tempGroupService = (GroupServiceLocal) > >> > > > > initialContext.lookup(GroupServiceLocal.class.getCanonicalName()); > >> > > > PersonServiceLocal tempPersonService = > (PersonServiceLocal) > >> > > > > initialContext.lookup(PersonServiceLocal.class.getCanonicalName()); > >> > > > GroupPK tempPK=new GroupPK(); > >> > > > > >> > > > Person tempPerson=new Person(); > >> > > > tempPerson.getId().setPersonName("Marcel"); > >> > > > tempPerson.setAgeNumber((short) 29); > >> > > > tempPerson.setRemarkText("TEST"); > >> > > > > >> > > > Group tempGroup=new Group(); > >> > > > tempGroup.getId().setGroupName("AA Team"); > >> > > > tempGroup.getId().setGroupNumber((short)1); > >> > > > tempGroup.getId().setValidFromDate(new Date()); > >> > > > tempGroup.setRemarkText("AA Team"); > >> > > > tempGroup.getPersons().add(tempPerson); > >> > > > tempPerson.setGroup(tempGroup); > >> > > > tempGroupService.createGroup(tempGroup); > >> > > > > >> > > > When running the test with the following property in the > >> > > persistence.xml: > >> > > > > >> > > > <property name="openjpa.MetaDataFactory" value="jpa"/> > >> > > > > >> > > > everything works fine. > >> > > > > >> > > > But when I change the property into: > >> > > > > >> > > > <property name="openjpa.MetaDataFactory" value= > >> > > > "org.apache.openjpa.persistence.PersistenceMetaDataFactory"/> > >> > > > > >> > > > (which should be essentially the same, according to the document > >> > > mentioned > >> > > > in the mail before) the test fails with following error message: > >> > > > > >> > > > <openjpa-1.2.1-r752877:753278 nonfatal general error> > >> > > > org.apache.openjpa.persistence.PersistenceException: > >> > > > DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC: > >> > > > I01W90.GROUPSQLCA OUTPUT[Errp=DSNXERT2, Errd=-335, 0, 0, -1, 0, > 0] > >> > > > DB2 SQL error: SQLCODE: -516, SQLSTATE: 26501, SQLERRMC: > null > >> > > > DB2 SQL error: SQLCODE: -518, SQLSTATE: 07003, SQLERRMC: > null > >> > > > FailedObject: prepstmnt 18898317 INSERT INTO i01w90.Group > >> > > > (groupName, groupNumber, validFromDate, remarkText, date, time, > >> user) > >> > > > VALUES (?, ?, ?, ?, ?, ?, ?) > >> > > > > >> > > > >> > > >> > [org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement] > >> > > > > >> > > > Obviously OpenJPA now does not use the column names I specified > (for > >> > > > example "TE_RMK") but instead uses the Java attribute name > >> > > ("remarkText"). > >> > > > > >> > > > Best regards Marcel > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > From: Rick Curtis <curti...@gmail.com> > >> > > > To: users@openjpa.apache.org > >> > > > Date: 10.08.2011 16:12 > >> > > > Subject: Re: Problems when using "openjpa.MetaDataFactory" > >> > > Property > >> > > > > >> > > > > >> > > > > >> > > > Can you post a unit test to help us better understand where > you're > >> > > running > >> > > > into problems? > >> > > > > >> > > > Thanks, > >> > > > Rick > >> > > > > >> > > > On Wed, Aug 10, 2011 at 4:49 AM, Marcel Urbanek > >> > > > <dt0...@retail-sc.com>wrote: > >> > > > > >> > > > > Hi, > >> > > > > > >> > > > > I want to overwrite the MetaDataFactory like described here: > >> > > > > > >> > > > > > >> > > > > >> > > > > >> > > > >> > > > >> > > >> > > >> > >> > > http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_meta.html > > >> > >> > > >> > > > >> > > > > >> > > > > > >> > > > > But it turned out it doesn't work. I managed to develop a test > >> > > scenario > >> > > > > which easily produces the behaviour I encountered. > >> > > > > > >> > > > > What _does_ work is the following: > >> > > > > > >> > > > > Adding > >> > > > > <property name="openjpa.MetaDataFactory" value="jpa"/> > >> > > > > to persistence.xml. > >> > > > > > >> > > > > When setting this property my junit test (persisting a simple > >> > > > association, > >> > > > > using @Column Annotation to use differing column names) does > work. > >> > > > > > >> > > > > > >> > > > > According to the document above, this property Tag should be > >> > > equivalent > >> > > > to > >> > > > > the setting above: > >> > > > > > >> > > > > <property name="openjpa.MetaDataFactory" > >> > > > > > >> value="org.apache.openjpa.persistence.PersistenceMetaDataFactory"/> > >> > > > > > >> > > > > But when using this configuration my junit test fails. The > >> differing > >> > > > > Column Names set by the @Column.name Attribute are no longer > >> found. > >> > > > > Instead the Java Attribute-Names are used in the SQL. > >> > > > > > >> > > > > My problem is, that I want to implement a custom > MetaDataFactory > >> and > >> > > > this > >> > > > > doesn't work either (which is expected, because I extend > >> > > > > PersistenceMetaDataFactory). Is there something I missed? > >> > > > > > >> > > > > (I'm using openjpa 2.11 with openejb 4.0.0 snapshot) > >> > > > > > >> > > > > Best regards Marcel > >> > > > > -- > >> > > > > RSC Commercial Services GmbH & Co. OHG, Wanheimer Strasse 70, > >> > D-40468 > >> > > > > Duesseldorf - Sitz: Duesseldorf - Registergericht: Duesseldorf > HRA > >> > > 12655 > >> > > > > Persoenlich haftende Gesellschafter: > >> > > > > C&A Retail GmbH - Sitz: Zug/Schweiz - Handelsregister Kanton > Zug: > >> > > > > CH-170.4.010.137-5 > >> > > > > Geschaeftsfuehrer: Bart F. Brenninkmeijer, Martijn N. N. > >> > > Brenninkmeijer, > >> > > > > Tjeerd E. van der Zee, Robert H. A. M. Smeele, Anthony H. Stam, > >> > > > > FRM PARTICIPATIONS S.A. - Sitz: Luxemburg/Luxemburg - Handels- > und > >> > > > > Firmenregister Luxemburg: B 58158 > >> > > > > Verwaltungsratsmitglieder: Rafael G. E. Bogaerts, John Drury, > >> Michel > >> > > de > >> > > > > Groote, Johny Seré, Robert H. A. M. Smeele > >> > > > > > >> > > > > > >> > > > > >> > > > > >> > > > -- > >> > > > *Rick Curtis* > >> > > > > >> > > > > >> > > > -- > >> > > > RSC Commercial Services GmbH & Co. OHG, Wanheimer Strasse 70, > >> D-40468 > >> > > > Duesseldorf - Sitz: Duesseldorf - Registergericht: Duesseldorf > HRA > >> > 12655 > >> > > > Persoenlich haftende Gesellschafter: > >> > > > C&A Retail GmbH - Sitz: Zug/Schweiz - Handelsregister Kanton Zug: > >> > > > CH-170.4.010.137-5 > >> > > > Geschaeftsfuehrer: Bart F. Brenninkmeijer, Martijn N. N. > >> > Brenninkmeijer, > >> > > > Tjeerd E. van der Zee, Robert H. A. M. Smeele, Anthony H. Stam, > >> > > > FRM PARTICIPATIONS S.A. - Sitz: Luxemburg/Luxemburg - Handels- > und > >> > > > Firmenregister Luxemburg: B 58158 > >> > > > Verwaltungsratsmitglieder: Rafael G. E. Bogaerts, John Drury, > Michel > >> > de > >> > > > Groote, Johny Seré, Robert H. A. M. Smeele > >> > > > > >> > > > > >> > > > >> > > > >> > > -- > >> > > *Rick Curtis* > >> > > > >> > > > >> > > -- > >> > > RSC Commercial Services GmbH & Co. OHG, Wanheimer Strasse 70, > D-40468 > >> > > Duesseldorf - Sitz: Duesseldorf - Registergericht: Duesseldorf HRA > >> 12655 > >> > > Persoenlich haftende Gesellschafter: > >> > > C&A Retail GmbH - Sitz: Zug/Schweiz - Handelsregister Kanton Zug: > >> > > CH-170.4.010.137-5 > >> > > Geschaeftsfuehrer: Bart F. Brenninkmeijer, Martijn N. N. > >> Brenninkmeijer, > >> > > Tjeerd E. van der Zee, Robert H. A. M. Smeele, Anthony H. Stam, > >> > > FRM PARTICIPATIONS S.A. - Sitz: Luxemburg/Luxemburg - Handels- und > >> > > Firmenregister Luxemburg: B 58158 > >> > > Verwaltungsratsmitglieder: Rafael G. E. Bogaerts, John Drury, > Michel > >> de > >> > > Groote, Johny Seré, Robert H. A. M. Smeele > >> > > > >> > > > >> > > >> > > >> > -- > >> > *Rick Curtis* > >> > > >> > > >> > -- > >> > RSC Commercial Services GmbH & Co. OHG, Wanheimer Strasse 70, D-40468 > >> > Duesseldorf - Sitz: Duesseldorf - Registergericht: Duesseldorf HRA > 12655 > >> > Persoenlich haftende Gesellschafter: > >> > C&A Retail GmbH - Sitz: Zug/Schweiz - Handelsregister Kanton Zug: > >> > CH-170.4.010.137-5 > >> > Geschaeftsfuehrer: Bart F. Brenninkmeijer, Martijn N. N. > Brenninkmeijer, > >> > Tjeerd E. van der Zee, Robert H. A. M. Smeele, Anthony H. Stam, > >> > FRM PARTICIPATIONS S.A. - Sitz: Luxemburg/Luxemburg - Handels- und > >> > Firmenregister Luxemburg: B 58158 > >> > Verwaltungsratsmitglieder: Rafael G. E. Bogaerts, John Drury, Michel > de > >> > Groote, Johny Seré, Robert H. A. M. Smeele > >> > > >> > > >> > >> > >> -- > >> RSC Commercial Services GmbH & Co. OHG, Wanheimer Strasse 70, D-40468 > >> Duesseldorf - Sitz: Duesseldorf - Registergericht: Duesseldorf HRA > 12655 > >> Persoenlich haftende Gesellschafter: > >> C&A Retail GmbH - Sitz: Zug/Schweiz - Handelsregister Kanton Zug: > >> CH-170.4.010.137-5 > >> Geschaeftsfuehrer: Bart F. Brenninkmeijer, Martijn N. N. > Brenninkmeijer, > >> Tjeerd E. van der Zee, Robert H. A. M. Smeele, Anthony H. Stam, > >> FRM PARTICIPATIONS S.A. - Sitz: Luxemburg/Luxemburg - Handels- und > >> Firmenregister Luxemburg: B 58158 > >> Verwaltungsratsmitglieder: Rafael G. E. Bogaerts, John Drury, Michel de > >> Groote, Johny Seré, Robert H. A. M. Smeele > >> > >> > > > >