These are my entities:
public class Account extends AbstractEntity<Long> { @Id @SequenceGenerator(name = "accountSequence", sequenceName = "SQ_ACCOUNTS", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "accountSequence") @Column(name = "ACC_ID", nullable = false) private Long id; ... } public class Integration extends AbstractEntity<Long> { @Id @SequenceGenerator(name = "integrationSequence", sequenceName="SQ_INTEGRATIONS", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "integrationSequence") @Column(name = "INT_ID", nullable = false) private Long id; ... public void addIntegration(Integration integration) { IntegrationAccount association = new IntegrationAccount();
And this is the entity for the join table
@Entity @Table(name = "INT_ACCOUNTS") public class IntegrationAccount { @EmbeddedId protected IntAccountsPK intAccountsPK; @JoinColumn(name = "ACC_ID", referencedColumnName = "ACC_ID", insertable = false, updatable = false) @ManyToOne private Account account; @JoinColumn(name = "INT_ID", referencedColumnName = "INT_ID", insertable = false, updatable = false) @ManyToOne private Integration integration; ... } @Embeddable public class IntAccountsPK implements Serializable { @Column(name = "INT_ID", nullable = false) private Long intId; @Column(name = "ACC_ID", nullable = false) private Long accId; ... }
And when I do:
account.addIntegrations(integrations.getTarget()); account.setCustomer(customer); accountService.save(account);
I got this in my journal Called: org.hibernate.id.IdentifierGenerationException: null id is generated for: class com.dhl.dcc.domain.IntegrationAccount
I donβt have much knowledge about this type of matching, can you tell me how to improve this matching (the entity for the join table must be saved) and how to save the account with the appropriate integration? Thanks.
source share