Hi,
I am using hibernate 5 and below is my issue.
I have id field in postgres db as uuid and have corresponding POJO as UUID as variable and getter/setter as String. I have following POjO :
Code:
public class LoginAuditInfo implements LoginAudit {
/**
* Automatically generated Id7
*/
private UUID Id;
public String getId() {
return String.valueOf(this.Id);
// return this.Id;
}
public void setId(String id) {
Id = UUID.fromString(id);
// Id = id;
}
private String userId;
/**
* Session Id
*/
private String sessionId;
/**
* Time User Logged In
*/
private Date LogInTime;
/**
* Time User Logged Out
*/
private Date LogOutTime;
private Date loginFailTime;
/**
* @return the userId
*/
public String getUserId() {
return userId;
}
/**
* @param userId
* the userId to set
*/
public void setUserId(String userId) {
this.userId = userId;
}
/**
* @return the sessionId
*/
public String getSessionId() {
return sessionId;
}
/**
* @param sessionId
* the sessionId to set
*/
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
/**
* @return the logInTime
*/
public Date getLogInTime() {
return LogInTime;
}
/**
* @param logInTime
* the logInTime to set
*/
public void setLogInTime(Date logInTime) {
LogInTime = logInTime;
}
/**
* @return the logOutTime
*/
public Date getLogOutTime() {
return LogOutTime;
}
/**
* @param logOutTime
* the logOutTime to set
*/
public void setLogOutTime(Date logOutTime) {
LogOutTime = logOutTime;
}
/**
* @return the logFailTime
*/
public Date getLoginFailTime() {
return loginFailTime;
}
/**
* @param sets
* the logFailTime
*/
public void setLoginFailTime(Date _loginFailTime) {
loginFailTime = _loginFailTime;
}
}
The following is my hbm :
Code:
[color=#404040]<hibernate-mapping>
<class name="LoginAuditInfo" table="user1">
<id name="Id" type="pg-uuid" >
<column name="Id" sql-type="uuid" not-null="true" />
<generator class="uuid2"></generator>
</id>
<property name="userId"></property>
<property name="sessionId">
<column name="session_id"></column>
</property>
<property name="LogOutTime">
<column name="log_out_time"></column>
</property>
<property name="loginFailTime">
<column name="login_fail_time"></column>
</property>
<property name="LogInTime">
<column name="log_in_time"></column>
</property>
</class>
</hibernate-mapping>
[/color]
While running the code I got the following error:
Code:
Caused by: IllegalArgumentException occurred while calling setter for property [LoginAuditInfo.Id (expected type = java.lang.String)]; target = [com.accenture.amap.LoginAuditInfo@10667848], property value = [8174ff23-9f62-4f21-9520-b1aff9318d06]
at org.hibernate.property.access.spi.SetterMethodImpl.set(SetterMethodImpl.java:99)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:258)
at org.hibernate.persister.entity.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:4651)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:172)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:667)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:659)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:654)
at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:619)
at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:615)
at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:340)
... 14 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.property.access.spi.SetterMethodImpl.set(SetterMethodImpl.java:44)
... 29 more
But the same configuration works fine with annotation. I do not want to use annotation as I have support for multiple databases. Is there any way to use the above configuration or it is necessary to have getter/setter also as UUID. Please suggest.Thanks & Regards,
Ankit