[Javalist] Criteria API - valahogy nem értem...

Viczián István viczian.istvan at gmail.com
2012. Már. 15., Cs, 15:44:45 CET


Szia!

"Apress - Pro JPA 2 Mastering the Java Persistence API (November 2009).pdf"
(Itt van a papíros is előttem, nem warez.)
A könyvet minden JPA fejlesztőnek javaslom.
270. oldal:


Generating the Canonical Metamodel
If you choose to use the generated metamodel in your queries, you
should be aware of some of the
details of the development process in case inconsistency or
configuration issues crop up. The canonical
metamodel classes will need to be updated or regenerated when certain
changes to entities have
occurred during development. For example, changing the name of a field
or property, or changing its
shape, would require an updated canonical metamodel class for that entity.
The generation tools offered by providers may vary widely in function
or in operation. Generation
may involve reading the persistence.xml file, as well as accessing
annotations on entities and XML
mapping files to determine what the metamodel classes should look
like. Since the specification does
not require such tools to even exist, a provider may choose to not
support it at all, expecting that if
developers want to use the canonical metamodel classes they will
handcode them. Most providers do
offer some kind of generation tool, though; it's just a matter of
understanding how that vendor-specific
tool works. It might run statically as a separate command line tool,
or it might use the compiler hook
offered in Java SE 6 to look at the entities and generate the classes
at compile-time. For example, to run
the command line mode of the tool shipped with the EclipseLink
Reference Implementation, you could
set the javac "-processor" and "-proc:only" options. These two options
indicate the EclipseLink
code/annotation processor1
 for the compiler to invoke, and instruct the compiler to call only the
processor but not do any actual compilation.
    javac -processor
org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
             -proc:only
             -classpath lib/*.jar;punit
             *.java
The options are on separate lines to make them easier to see. It is
assumed that the lib directory
contains the necessary EclipseLink JAR and JPA 2.0 interface JAR, and
that the META-INF/persistence.xml
is in the punit directory.
Metamodel generation tools will also typically run in an IDE, and
there will likely be IDE-specific
configuration necessary to direct the incremental compiler to use the
tool's annotation processor. In
some IDEs, there must be an additional code/annotation processor JAR
to configure. The generated
metamodel classes will need to go in a specific directory and be on
the build classpath so the criteria
queries that reference them can compile. Consult the IDE help files on
how annotation processors or
APT is supported, as well as the provider documentation on what to
configure in order to enable
generation in a given IDE.

--
Viczián István



2012/3/15 Gábor Garami <gabor.garami at hron.me>:
> Sziasztok,
>
> Valószínüleg megint valami alap dolgot nem értek.
>
> Olvasgatom a hivatalos JavaEE tutorialnak a Criteria API-ra vonatkozó
> részét, ezt ni: http://docs.oracle.com/javaee/6/tutorial/doc/gkjiv.html
>
> Azt látom, hogy a tutorial kézzel generálta meg a Metamodel osztályt. Erre
> van valami mód, hogy automatikusan generáljam? Olvasgattam, hogy a
> Hibernate-hoz van ilyen cucc, meg kulon eclipselink-hez is, ez akkor azt
> jelenti, hogy minden ilyen JPA implementaciohoz a megfelelot kell hasznalni?
> Vagy van valami generikus is, csak nem talalom? Miben kulonboznek ezek
> egyaltalan egymastol? Mert ahogy elnezem, ez valami statikus kod,
> gyakorlatilag ha nagyon megeroltetem magamat, ossze tudok dobni egy
> scriptet, ami a megadott osztaly kodjabol nemi regexes varazslat
> segitsegevel legeneralja azt az osztalyt. Vagy van valami mas titkos dolog
> is, amit en nem latok?
>
> Elore is koszonom a segitseget.
>
> Udv,
>
> Garami Gábor
> E-mail: gabor.garami at hron.me
> Tel: +36 20 235 9621
> MSN: hrgy at vipmail.hu
> Skype: hron84
>
>
> _______________________________________________
> Javalist mailing list
> Javalist at lists.javaforum.hu
> http://lists.javaforum.hu/mailman/listinfo/javalist
>


További információk a(z) Javalist levelezőlistáról