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 <[email protected]>
To: [email protected]
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
<[email protected]>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 <[email protected]>
> To: [email protected]
> 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
> <[email protected]>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 <[email protected]>
> > To: [email protected]
> > 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
> > <[email protected]>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 <[email protected]>
> > > To: [email protected]
> > > 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
> > > <[email protected]>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