1 2 Previous Next 21 Replies Latest reply: May 16, 2012 9:21 AM by carlos cortez RSS

    POJO entity

    user575089
      I have a jpa POJO entity. It has an id field .

      I want this id field to be mapped with an auto incremented column of a database table.


      What annotation syntax to be used for such POJO id field ?
        • 1. Re: POJO entity
          Nitin Khare
          A lot depend on what technique you are using for your persistence and mapping your object to database - Hibrenate, JPA, ... ?
          The typical annotation would be something like
          @Id @GeneratedValue
          private Long id;
          • 2. Re: POJO entity
            gimbal2
            Well the OP does mention the use of JPA.

            But this is something incredibly basic, answered by any JPA book or even a Google search for "java jpa mysql".
            • 3. Re: POJO entity
              user575089
              Nitin Khare wrote:
              A lot depend on what technique you are using for your persistence and mapping your object to database - Hibrenate, JPA, ... ?
              The typical annotation would be something like
              @Id @GeneratedValue
              private Long id;
              No hibernate.
              Pojo and entitymanager.
              What is the right syntax?
              • 4. Re: POJO entity
                user575089
                gimbal2 wrote:
                Well the OP does mention the use of JPA.

                But this is something incredibly basic, answered by any JPA book or even a Google search for "java jpa mysql".
                I found this. I guess this syntax is correct.
                @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="id_prueba") private Integer id;

                By the way what is the name of orale(sun) JPA implementation?
                • 5. Re: POJO entity
                  carlos cortez
                  By the way what is the name of orale(sun) JPA implementation?
                  TopLink

                  Regars
                  Carlos
                  • 6. Re: POJO entity
                    user575089
                    ccortez wrote:
                    By the way what is the name of orale(sun) JPA implementation?
                    TopLink

                    Regars
                    Carlos
                    I am getting confused.

                    I wanted to know what do you call when we write such pojo classes and use entitymanager to persist entities ---- these are orale(sun)'s own implementation ..is not it ? these have some names ...right ? I dont think you call these as Toplink ..So what do you call it ?
                    • 7. Re: POJO entity
                      carlos cortez
                      Hi,

                      You asked for the name of Oracle's JPA implementation right? that is TopLink as Hibernate is the RedHat's JPA implementation.
                      I wanted to know what do you call when we write pojo classes and use entitymanager to persist entities ---- these are jpa implementation ..is not it ? these have some names ...right ? I dont think you call these as Toplink ..So what do you call it ?
                      You have to call the persist method of the EntityManager class in order to persist entities.

                      Here are the methods of the EntityManager class:
                      http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html

                      and here and example of the use of the class to persist an entity:
                      http://openejb.apache.org/examples-trunk/injection-of-entitymanager/

                      Regards
                      Carlos
                      • 8. Re: POJO entity
                        user575089
                        ccortez wrote:
                        Hi,
                        You have to call the persist method of the EntityManager class in order to persist entities.
                        Here are the methods of the EntityManager class:
                        http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html
                        and here and example of the use of the class to persist an entity:
                        http://openejb.apache.org/examples-trunk/injection-of-entitymanager/
                        so in EJB 3.0 entities are persisted by using default apache openejb JPA implementation (but not oracle's own JPA implementation !) ?
                        • 9. Re: POJO entity
                          carlos cortez
                          so in EJB 3.0 entities are persisted by using apache openejb JPA implementation (but not oracle's own JPA implementation !) ?
                          The openejb is just a container to EJBs, you can use the container from an OAS or Weblogic, the example is just to let you know how to use the method persist using EJB

                          Regards
                          Carlos
                          • 10. Re: POJO entity
                            user575089
                            ccortez wrote:
                            so in EJB 3.0 entities are persisted by using apache openejb JPA implementation (but not oracle's own JPA implementation !) ?
                            the example is just to let you know how to use the method persist using EJB
                            Ok. no issue.

                            Is that example not a JPA persistence then ?
                            • 11. Re: POJO entity
                              carlos cortez
                              Is that example not a JPA persistence then ?
                              That is a JPA example using EJB3 and using openEJB container, but you can change this container for one by Oracle, also this link might help you:

                              http://docs.oracle.com/cd/B32110_01/web.1013/b28221/cmp30cfg.htm

                              Regards
                              Carlos
                              • 12. Re: POJO entity
                                user575089
                                That is a JPA example using EJB3 and using openEJB container
                                Ok . no issue.

                                Does JAVA EE download has a JPA implementation in-built ?
                                • 13. Re: POJO entity
                                  gimbal2
                                  user575089 wrote:
                                  That is a JPA example using EJB3 and using openEJB container
                                  Ok . no issue.

                                  Does JAVA EE download has a JPA implementation in-built ?
                                  There is no JavaEE download. JPA, EJB, etc. etc. are specifications and grouped under the larger specification called the Java Enterprise Edition. The only real download that exists for it is the specification document itself.

                                  There are multiple implementations out there of the JEE specification. Glassfish (which Oracle likes to called the "JEE SDK"), JBoss, Weblogic, Websphere, etc. etc. Each of these implementing containers has the job of providing JPA services: in other words it must make it possible to use JPA in enterprise applications. This means they'll need to include a persistence provider, but which persistence provider is actually used is up to the people who deliver the container. If its Glassfish its going to be EclipseLink, if its JBoss it is going to be Hibernate, etc. etc. The container's documentation should mention which persistence provider is used and how to set it up.
                                  • 14. Re: POJO entity
                                    user575089
                                    gimbal2 wrote:
                                    user575089 wrote:
                                    That is a JPA example using EJB3 and using openEJB container
                                    Ok . no issue.

                                    Does JAVA EE download has a JPA implementation in-built ?
                                    Glassfish (which Oracle likes to called the "JEE SDK")
                                    I guess you mean this download ..

                                    http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eesdk-419427.html#j2eesdk-1_4_03-ml-oth-JPR

                                    Product / File Description
                                    +     +
                                    File Size
                                    +     +
                                    Download
                                    J2EE SDK 1.4_03      141.79 MB       j2eesdk-1_4_03-linux-ml.bin
                                    J2EE SDK 1.4_03      143.12 MB       j2eesdk-1_4_03-solaris-i586-ml.bin
                                    J2EE SDK 1.4_03      158.01 MB       j2eesdk-1_4_03-solaris-sparc-ml.bin
                                    J2EE SDK 1.4_03      132.21 MB       j2eesdk-1_4_03-windows-ml.exe

                                    If its Glassfish its going to be EclipseLink,
                                    Do you mean this download has EclipseLink JPA implementation. ?
                                    1 2 Previous Next