javaeetutorial
  1. javaeetutorial
  2. JAVAEETUTORIAL-7

http://java.sun.com/javaee/6/docs/tutorial/doc/gjivm.html Syntax errors

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 6.0.4
    • Fix Version/s: 6.0.5
    • Component/s: doc
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      7

      Description

      This was originally from issue 5 and now split up (Example 22-10 Joining a
      Query) A Maven project with sample code that does not compile is attached.

      Another syntax error, Please confirm this one.
      The following code does not compile:
      CriteriaQuery<String> cq = cb.createQuery(String.class);
      Metamodel m = em.getMetamodel();
      EntityType<Pet> Pet_ = m.entity(Pet.class);

      Root<Pet> pet = cq.from(Pet.class);
      cq.select(pet.get(Pet_.name));

      It should be : EntityType<Pet> pet_ = m.entity(Pet.class);//was Pet_
      Pet_ is a class defined previously in the tutorial

        Activity

        Hide
        rjdkolb added a comment -

        Created an attachment (id=2)
        Maven sample with code that does not compile

        Show
        rjdkolb added a comment - Created an attachment (id=2) Maven sample with code that does not compile
        Hide
        rjdkolb added a comment -

        added cc

        Show
        rjdkolb added a comment - added cc
        Hide
        Ian Evans added a comment -

        Reassigning to me.

        Show
        Ian Evans added a comment - Reassigning to me.
        Hide
        rjdkolb added a comment -

        Example 22-8, 22-11 ,22-12 , 22-13 , 22-14, 22-15 ,22-16 ,22-17 ,22-18, 22-19
        suffers from the same problem
        It calls : EntityType<Pet> Pet_ = m.entity(Pet.class);
        It should be EntityType<Pet> pet_ = m.entity(Pet.class);

        The class Pet_ is defined in :
        http://java.sun.com/javaee/6/docs/tutorial/doc/gjiup.html

        Show
        rjdkolb added a comment - Example 22-8, 22-11 ,22-12 , 22-13 , 22-14, 22-15 ,22-16 ,22-17 ,22-18, 22-19 suffers from the same problem It calls : EntityType<Pet> Pet_ = m.entity(Pet.class); It should be EntityType<Pet> pet_ = m.entity(Pet.class); The class Pet_ is defined in : http://java.sun.com/javaee/6/docs/tutorial/doc/gjiup.html
        Hide
        Ian Evans added a comment -

        The error you see in the attached project is actually unrelated to the name of
        the Pet_ metamodel class. If you already have a statically generated metamodel
        class za.co.enerweb.javadocissue5.Pet_, you can't dynamically obtain
        za.co.enerweb.javadocissue5.Pet_ using Metamodel.entity().

        If you're using statically generated metamodel classes, there's no need to
        obtain it dynamically using:
        EntityType<Pet> Pet_ = m.entity(Pet.class);
        You can simply import the static metamodel classes and use them.

        Your test project works when you instead have:
        EntityType<Pet> pet_ = m.entity(Pet.class);
        because za.co.enerweb.javadocissue5.pet_ is a dynamically generated metamodel
        class with a different name than the statically generated class
        za.co.enerweb.javadocissue5.Pet_, which has already been instantiated.

        If you want to use dynamically generated metamodel classes, you can't also use
        statically generated classes packaged in the same project.

        Does that make sense?

        Show
        Ian Evans added a comment - The error you see in the attached project is actually unrelated to the name of the Pet_ metamodel class. If you already have a statically generated metamodel class za.co.enerweb.javadocissue5.Pet_, you can't dynamically obtain za.co.enerweb.javadocissue5.Pet_ using Metamodel.entity(). If you're using statically generated metamodel classes, there's no need to obtain it dynamically using: EntityType<Pet> Pet_ = m.entity(Pet.class); You can simply import the static metamodel classes and use them. Your test project works when you instead have: EntityType<Pet> pet_ = m.entity(Pet.class); because za.co.enerweb.javadocissue5.pet_ is a dynamically generated metamodel class with a different name than the statically generated class za.co.enerweb.javadocissue5.Pet_, which has already been instantiated. If you want to use dynamically generated metamodel classes, you can't also use statically generated classes packaged in the same project. Does that make sense?
        Hide
        rjdkolb added a comment -

        Thanks for the explanation.
        But the following does not work either (dynamically generated metamodel class)
        private void brokenExample()

        { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Metamodel m = em.getMetamodel(); EntityType<Pet> pet_ = m.entity(Pet.class); Root<Pet> pet = cq.from(Pet.class); Join<Pet, Person> owner = pet.join(pet_.person);//Owner does not exist. I assume this is Person }

        Show
        rjdkolb added a comment - Thanks for the explanation. But the following does not work either (dynamically generated metamodel class) private void brokenExample() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Metamodel m = em.getMetamodel(); EntityType<Pet> pet_ = m.entity(Pet.class); Root<Pet> pet = cq.from(Pet.class); Join<Pet, Person> owner = pet.join(pet_.person);//Owner does not exist. I assume this is Person }
        Hide
        rjdkolb added a comment -

        I've been digging around about this one and I don't think this is a doc issue.
        From Pro JPA 2 : Page 270 I see each vendor needs to implement this

        From Eclipse Link -> It show how to set it up in Eclipse
        http://wiki.eclipse.org/UserGuide/JPA/Using_the_Canonical_Model_Generator_%28ELUG%29

        I am going to close this issue, as I don't think it is a docs issue.

        Show
        rjdkolb added a comment - I've been digging around about this one and I don't think this is a doc issue. From Pro JPA 2 : Page 270 I see each vendor needs to implement this From Eclipse Link -> It show how to set it up in Eclipse http://wiki.eclipse.org/UserGuide/JPA/Using_the_Canonical_Model_Generator_%28ELUG%29 I am going to close this issue, as I don't think it is a docs issue.
        Hide
        rjdkolb added a comment -

        FYI : http://netbeans.org/bugzilla/show_bug.cgi?id=178108&GoAheadAndLogIn=1

        Although this issue is invalid, perhaps a note that it won't just work out the
        box is in order. It may save some head scratching and wondring why it does not
        work as advertised in the tutorial.

        I have personally used the Maven plugin as described by 'Petr Jiricka' and it
        works well. There is also a Ant script that does the same there.

        Perhaps this is a case of the IDE's lagging behind the technology.

        Show
        rjdkolb added a comment - FYI : http://netbeans.org/bugzilla/show_bug.cgi?id=178108&GoAheadAndLogIn=1 Although this issue is invalid, perhaps a note that it won't just work out the box is in order. It may save some head scratching and wondring why it does not work as advertised in the tutorial. I have personally used the Maven plugin as described by 'Petr Jiricka' and it works well. There is also a Ant script that does the same there. Perhaps this is a case of the IDE's lagging behind the technology.
        Hide
        pjiricka added a comment -

        Yes, metamodel generation is tricky and setting it up correctly in your build is not easy. Bugs in Maven,
        EclipseLink and java are preventing this from working well - the IDE is just trying to coordinate and
        orchestrate all these tools and runtimes. The following comment describes how to set up metamodel
        generation with Maven: https://netbeans.org/bugzilla/show_bug.cgi?id=181861#c8

        Show
        pjiricka added a comment - Yes, metamodel generation is tricky and setting it up correctly in your build is not easy. Bugs in Maven, EclipseLink and java are preventing this from working well - the IDE is just trying to coordinate and orchestrate all these tools and runtimes. The following comment describes how to set up metamodel generation with Maven: https://netbeans.org/bugzilla/show_bug.cgi?id=181861#c8

          People

          • Assignee:
            Ian Evans
            Reporter:
            rjdkolb
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: