Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] How to use the criteria api metamodel in a java se project?

Gabriele,
Yes, the Criteria and Metamodel API's are part of JPA 2.0 which is part of JEE6. JPA 1.0/2.0 has always supported SE persistence via the javax.persistence specification package import. Your code on the stackoverflow post looks fine, you do not require canonical generated classes as your EntityType<Meaning> dynamic metamodel Type class is ok to use.

   A Java SE test model is in SVN below.
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel

The Java SE metamodel (dynamic in-memory non-canonical) test cases are below.
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel

For persistence.xml you do not need to use the JPA 2.0 schema unless you require use of new elements/attributes introduced in 2.0 - there are none for Criteria/Metamodel except for canonical generation (if you require it). The "em.getMetamodel()" call does not require static generated classes - it will generate them in-memory as your Meaning_ variable.
http://wiki.eclipse.org/UserGuide/JPA/Using_the_Canonical_Model_Generator_(ELUG)#EclipseLink_custom_processor_options

Either of these headers will work in persistence.xml - use the 2.0 one if you use one of the 5 canonical metamodel properties introduced in 2.0

<!-- persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"--> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd";>

For usage, there are 3 ways to use the Metamodel API detailed below (Static - via canonical modelgen generated "_" classes, dynamic in memory typesafe and dynamic in memory non-typesafe (using String get methods)
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#API_Usage

   I do not see anything JPA 2.0 related in your Entity.
If you are seeing compile-time or run-time errors running this query - you may post the stacktrace and logs if you would like.
   thank you
   /michael


Gabriele Kahlout wrote:
http://stackoverflow.com/questions/3458742/why-the-compiler-doesnt-recognize-the-metamodel-attributes



Back to the top