javaeetutorial
  1. javaeetutorial
  2. JAVAEETUTORIAL-5

Syntax errors in code, Java 6 tutorial, Criteria API chapter

    Details

    • Issuezilla Id:
      5

      Description

      These are very small issues:
      There are code syntax errors on this page :
      http://java.sun.com/javaee/6/docs/tutorial/doc/gjivm.html


      Example 22-14 Using the Expression.in Method

      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);
      cq.where(pet.get(Pet_.color).in("brown", "black");

      – > should be
      cq.where(pet.get(Pet_.color).in("brown", "black"));

      Another example :
      cq.orderBy(cb.desc(pet.get(Pet_.birthday));

      – > should be
      cq.orderBy(cb.desc(pet.get(Pet_.birthday)));

      Another example :
      cq.orderBy(cb.asc(address.get(Address_.postalCode));

      – > should be
      cq.orderBy(cb.asc(address.get(Address_.postalCode)));

        Activity

        Hide
        Ian Evans added a comment -

        Another syntax error :
        in Example 22–2

        @Static Metamodel(Pet.class) should be @StaticMetamodel(Pet.class)

        Show
        Ian Evans added a comment - Another syntax error : in Example 22–2 @Static Metamodel(Pet.class) should be @StaticMetamodel(Pet.class)
        Hide
        Ian Evans added a comment -

        Another syntax error. This causes run time issues
        -> { "7250", "[

        {0}

        ] uses a non-entity [

        {1}

        ] as target entity in the relationship
        attribute [

        {2}

        ]."}
        @Entity
        public class Pet

        { @Id protected Long id; protected String name; protected String color; @ManyToOne protected Set<Person> owners; ... }

        Should be
        @Entity
        public class Pet

        { @Id protected Long id; protected String name; protected String color; @OneToMany protected Set<Person> owners; ... }
        Show
        Ian Evans added a comment - Another syntax error. This causes run time issues -> { "7250", "[ {0} ] uses a non-entity [ {1} ] as target entity in the relationship attribute [ {2} ]."} @Entity public class Pet { @Id protected Long id; protected String name; protected String color; @ManyToOne protected Set<Person> owners; ... } Should be @Entity public class Pet { @Id protected Long id; protected String name; protected String color; @OneToMany protected Set<Person> owners; ... }
        Hide
        Ian Evans added a comment -

        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

        Show
        Ian Evans added a comment - 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
        Hide
        Ian Evans added a comment -

        Looking into these code sample errors, closing GlassFish Looking into these code sample errors, closing GlassFish bug 11676 as Won't Fix
        so we can track it here. as Won't Fix
        so we can track it here.

        Show
        Ian Evans added a comment - Looking into these code sample errors, closing GlassFish Looking into these code sample errors, closing GlassFish bug 11676 as Won't Fix so we can track it here. as Won't Fix so we can track it here.
        Hide
        Ian Evans added a comment -

        I'm going to check with Linda DeMichiel (JPA spec lead), but this code should
        compile:
        CriteriaQuery<String> cq = cb.createQuery(String.class);
        Metamodel m = em.getMetamodel();
        EntityType<Pet> Pet_ = m.entity(Pet.class);

        What is the exact error you get?

        Show
        Ian Evans added a comment - I'm going to check with Linda DeMichiel (JPA spec lead), but this code should compile: CriteriaQuery<String> cq = cb.createQuery(String.class); Metamodel m = em.getMetamodel(); EntityType<Pet> Pet_ = m.entity(Pet.class); What is the exact error you get?
        Hide
        rjdkolb added a comment -

        > I'm going to check with Linda DeMichiel (JPA spec lead), but this code should
        > 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));
        >
        > What is the exact error you get?

        thanks.
        I get a error saying name is not a member pf Pet_
        Actually it is a member, but the class Pet_ is instantiated, but it should be
        instantiated pet_

        Show
        rjdkolb added a comment - > I'm going to check with Linda DeMichiel (JPA spec lead), but this code should > 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)); > > What is the exact error you get? thanks. I get a error saying name is not a member pf Pet_ Actually it is a member, but the class Pet_ is instantiated, but it should be instantiated pet_
        Hide
        Ian Evans added a comment -

        I think that error must come from using Pet_ in some other part of your code.
        The following code compiles without errors:
        public void test()

        { CriteriaQuery<String> cq = cb.createQuery(String.class); Metamodel m = em.getMetamodel(); EntityType<Address> Address_ = m.entity(Address.class); }
        Show
        Ian Evans added a comment - I think that error must come from using Pet_ in some other part of your code. The following code compiles without errors: public void test() { CriteriaQuery<String> cq = cb.createQuery(String.class); Metamodel m = em.getMetamodel(); EntityType<Address> Address_ = m.entity(Address.class); }
        Hide
        rjdkolb added a comment -

        Issues 6 and 7 have now been created to explain myself better.
        A few lines of code can mean a thousand words.

        Show
        rjdkolb added a comment - Issues 6 and 7 have now been created to explain myself better. A few lines of code can mean a thousand words.
        Hide
        Ian Evans added a comment -

        Fixed typo in SGML source for static metamodel class Pet_. This fix will be in
        the next update.

        Show
        Ian Evans added a comment - Fixed typo in SGML source for static metamodel class Pet_. This fix will be in the next update.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: