I am new to hibernate. I am trying to map the following entity but getting hibernate mapping exception. Help will be much appreciated. Remember, Iam using PostgreSQL
package st.malike.auth.server.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
@Entity
public class OAuth2AuthenticationRefreshToken implements Serializable {
// @Indexed
@javax.persistence.Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
private final String tokenId;
private final OAuth2RefreshToken oAuth2RefreshToken;
private final OAuth2Authentication authentication;
public OAuth2AuthenticationRefreshToken(OAuth2RefreshToken oAuth2RefreshToken, OAuth2Authentication authentication) {
this.oAuth2RefreshToken = oAuth2RefreshToken;
this.authentication = authentication;
this.tokenId = oAuth2RefreshToken.getValue();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTokenId() {
return tokenId;
}
public OAuth2RefreshToken getoAuth2RefreshToken() {
return oAuth2RefreshToken;
}
public OAuth2Authentication getAuthentication() {
return authentication;
}
}
And getting exception as below
Caused by: org.hibernate.MappingException: Could not determine type for: org.springframework.security.oauth2.common.OAuth2RefreshToken,
at table: oauth2authentication_refresh_token,
for columns: [org.hibernate.mapping.Column(o_auth2refresh_token)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:396) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:369) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.mapping.Property.isValid(Property.java:225) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:595) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.mapping.RootClass.validate(RootClass.java:265) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final]
... 162 common frames omitted
oAuth2RefreshTokenandauthentication, do you want them to be stored into the db? if not annotate them with@Transientor add the modifiertransientto their declarationOAuth2AuthenticationRefreshToken, andOAuth2Authenticationin your DB, you need to specify the mapping to hibernate (to which other hibernate entity it is linked). Is that what you intend to do ?