- This topic has 2 replies, 2 voices, and was last updated 16 years, 4 months ago by sliderrr.
-
AuthorPosts
-
sliderrrMemberI 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.
Brian FernandesModeratorsliderrr,
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
sliderrrMemberThe 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 🙂
-
AuthorPosts