In my current implementation, I have separate entity classes for each db table. I use JPA along with eclipselink-2.5.2. This works fine for me, but at some point, when the data is huge, it lags behind. So I decided to start using @Embedded, @Embeddable and @EmbeddedId. By doing this, I get an error message that is very strange for me. Here is the full stacktrace post: https://gist.githubusercontent.com/tjDudhatra/b955812e0d1a71cf97f1/raw/11ea458869e24baae744530417ac99bc877ed514/gistfile1.txt
To be specific, let me give you the exact scenario, in which case I get an exception. Consider this block of code that has three classes. One of them is annotated as @Entity, and the other two are annotated as @Embeddable. I know that in one class we cannot define @Id and @EmbeddedId, and I didn’t do this, then when I deploy the server I get an exception that only says that:
[class org.apache. {SomeClass}] has both @EmbdeddedId (by attribute [id]) and @Id (by attribute []. Both identifiers cannot be specified on the same object.
@Entity @Table(name="user") public class User { @ID public Long id; @Column(name="userCode") public String userCode; @ElementCollection @CollectionTable(name = "address", joinColumns = @JoinColumn(name = "user_id")) public List<Address> addressList; .... } @Embeddable public class Address { @EmbeddedId @Column(name = "id") public Long id; @Column(name="userId") public Long userId; @Column(name="address-line-1") public String addressLine1; @Column(name="address-line-2") public String addressLine2; @ElementCollection @CollectionTable(name = "phone", joinColumns = @JoinColumn(name = "user_id")) protected List<Phone> phoneList; .... } @Embeddable public class Phone { @EmbeddedId @Column(name = "id") public Long id; @Column(name="contact_no") public String contactNo; @Column(name="country_code") public int countryCode; @Column(name="address_id") public int addressId; .... }
Please let me know if more details are needed and any help would be greatly appreciated.
Thanks,
source share