I have configured composite primary key for my entity UserActivity as follows with composite key on msisdn & extReferenceId. Both are annotated with @Id in my entity. The IdClass is UserActivityId and it is annotated too as below. When I start the Spring Boot app, it is failing with error:
java.lang.IllegalArgumentException: This class [class com.compay.ipspaymentstatus.model.UserActivity] does not define an IdClass
But I have defined my IdClass and annotated it.
I have tried IdClass annotation and also mentioned IdClass in hibernate xml mapping as below nothing seemed to work and says IdClass not defined.
UserActivity.java
package com.compay.ipspaymentstatus.model;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@IdClass(UserActivityId.class)
@Table(name = "USERACTIVITY")
public class UserActivity implements Serializable {
private static final long serialVersionUID = -2547001532653675405L;
@Id
@Column(name = "MSISDN")
private String msisdn;
@Id
@Column(name = "EXT_REFERENCE_ID")
private String extReferenceID;
private String subscriberID;
private String deviceModelID;
public String getMsisdn() {
return msisdn;
}
public void setMsisdn(String msisdn) {
this.msisdn = msisdn;
}
public String getExtReferenceID() {
return extReferenceID;
}
public void setExtReferenceID(String extReferenceID) {
this.extReferenceID = extReferenceID;
}
public String getSubscriberID() {
return subscriberID;
}
public void setSubscriberID(String subscriberID) {
this.subscriberID = subscriberID;
}
public String getDeviceModelID() {
return deviceModelID;
}
public void setDeviceModelID(String deviceModelID) {
this.deviceModelID = deviceModelID;
}
}
UserActivityId.java
package com.compay.ipspaymentstatus.model;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.IdClass;
@IdClass(UserActivityId.class)
public class UserActivityId implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String msisdn;
private String extReferenceID;
public UserActivityId() {
}
public UserActivityId(String msisdn, String extReferenceID) {
this.msisdn = msisdn;
this.extReferenceID = extReferenceID;
}
public String getMsisdn() {
return msisdn;
}
public void setMsisdn(String msisdn) {
this.msisdn = msisdn;
}
public String getExtReferenceID() {
return extReferenceID;
}
public void setExtReferenceID(String extReferenceID) {
this.extReferenceID = extReferenceID;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof UserActivity)) {
return false;
}
UserActivity userActivity = (UserActivity) o;
return Objects.equals(msisdn, userActivity.getMsisdn()) &&
Objects.equals(extReferenceID, userActivity.getExtReferenceID());
}
@Override
public int hashCode() {
return Objects.hash(msisdn, extReferenceID);
}
}
UserActivity.hbm.xml
<hibernate-mapping>
<class name="com.compay.ipspaymentstatus.model.UserActivity" table="USERACTIVITY">
<composite-id class="com.compay.ipspaymentstatus.model.UserActivityId">
<key-property name="msisdn" column="MSISDN" type="string" />
<key-property name="extReferenceID" column="EXT_REFERENCE_ID" type="string" />
</composite-id>
<property name="subscriberID" type="string">
<column name="SUBSCRIBERID" length="20" not-null="true" />
</property>
<property name="deviceModelID" type="string">
<column name="DEVICEMODELID" length="30" not-null="true" />
</property>
</class>
</hibernate-mapping>
Error received while starting the springboot application
Caused by: java.lang.IllegalArgumentException: This class [class com.compay.ipspaymentstatus.model.UserActivity] does not define an IdClass
at org.hibernate.metamodel.internal.AbstractIdentifiableType.getIdClassAttributes(AbstractIdentifiableType.java:183) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation$IdMetadata.<init>(JpaMetamodelEntityInformation.java:259) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:88) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:188) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:139) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:123) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:64) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:305) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport$$Lambda$570/757150717.get(Unknown Source) ~[na:na]
at org.springframework.data.util.Lazy.getNullable(Lazy.java:211) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:119) ~[spring-data-jpa-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
... 45 common frames omitted