facebook

JPA reverse engineering issue

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #289001 Reply

    sliderrr
    Member

    I don’t really know if this is a bug or working as intended, mybe someone can explain this behavior:

    If I generate the entity classes with the JPA Reverse Engineering tools form a postgresql database it generates two files, one “default” class named like the table with an embedded id and one Id class with the actual table contents.
    Example:
    Database:

    CREATE TABLE customer
    (
      email character varying NOT NULL,
      prefix character varying NOT NULL,
      firstname character varying(30),
      lastname character varying(30),
      ....
    )

    Some index-fields, but pretty much a plain table.

    Now the class looks like this:

    customer.java:

    
    @Entity
    @Table(name = "customer", schema = "public", uniqueConstraints = @UniqueConstraint(columnNames = "id"))
    public class Customer implements java.io.Serializable {
    
        // Fields
    
        private CustomerId id;
           ....
        // Property accessors
        @EmbeddedId
        @AttributeOverrides( {
                @AttributeOverride(name = "id", column = @Column(name = "id", unique = true, nullable = false)),
                @AttributeOverride(name = "firstname", column = @Column(firstname = "firstname", nullable = false)),
    

    customerid.java

    
    @Embeddable
    public class CustomerId implements java.io.Serializable {
    
        // Fields
    
        private Integer id;
        private String firstname;
           ....
    

    Is there a specific reason for that (splitting into two files with EmbeddedId) or am I missing something else?

    Thanks in advance.

    #289021 Reply

    Brian Fernandes
    Moderator

    sliderrr,

    Yes, this is working as expected. This is because you have a composite primary key (a primary key with more than one column). In such cases the tooling will generate a separate entity for all columns in the primary key and “embed” that key into the primary entity.

    This makes it easier for you to reference a particular customer in relationships using a single CustomerId class.

    Hope this helps

    #289053 Reply

    sliderrr
    Member

    The tool was actually working correctly, the problem was in my case that the primary key was just a id-column with an unique constraint. The values were generated from a nextval-sequence table which caused the tool to compose the id from all columns becaus I could recognize the id.

    Thanks for the help 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: JPA reverse engineering issue

You must be logged in to post in the forum log in