| mapping file
<hibernate-mapping xmlns="http: package="com.isoft.example.domain.model">
<typedef class="com.isoft.repository.hibernate.usertype.EnumXType" name="enumType"/>
<class name="Person" table="Person">
<id name="id" type="java.lang.String">
<column name="Id" length="36" not-null="true"/>
<generator class="uuid2"/>
</id>
<version name="version" type="java.lang.Integer">
<column name="Version"/>
</version>
<property name="createdById" type="java.lang.String">
<column name="CreatedById" length="36" not-null="true"/>
</property>
<property name="createdOn" type="java.util.Date">
<column name="CreatedOn" not-null="true"/>
</property>
<property name="lastModifiedById" type="java.lang.String">
<column name="LastModifiedById" length="36"/>
</property>
<property name="lastModifiedOn" type="java.util.Date">
<column name="LastModifiedOn"/>
</property>
<property name="name" type="java.lang.String">
<column name="Name" length="32" not-null="true"/>
</property>
<property name="idNo" type="java.lang.String">
<column name="IdNo"/>
</property>
<property name="sex">
<column name="Sex"/>
<type name="com.isoft.repository.hibernate.usertype.EnumXType">
<param name="enumType">com.isoft.example.domain.enumeration.Sex</param>
</type>
</property>
</class>
</hibernate-mapping>
Person.Class
public class Person extends AbstractAggregateRoot {
public Person() {
}
public Person(String name) {
this();
this.name = name;
}
public Person(String name, String createdById, Date createdOn) {
this(name);
this.setCreatedById(createdById);
this.setCreatedOn(createdOn);
}
private String name;
private String idNo;
@Email
private String email;
private Sex sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdNo() {
return idNo;
}
public void setIdNo(String idNo) {
this.idNo = idNo;
}
public Sex getSex() {
return sex;
}
public void setSex(Sex sex) {
this.sex = sex;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
AbstractAggregateRoot.Class
@MappedSuperclass
public abstract class AbstractAggregateRoot {
private String id;
private String createdById;
private Date createdOn;
private String lastModifiedById;
private Date lastModifiedOn;
private Integer version;
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (this.id == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
AbstractEntity entityBase = (AbstractEntity) obj;
return this.id.equals(entityBase.getId());
}
@Override
public int hashCode() {
return this.id == null ? 0 : this.id.hashCode();
}
public String getId() {
return id;
}
private void setId(String id) {
this.id = id;
}
public String getCreatedById() {
return createdById;
}
public void setCreatedById(String createdById) {
this.createdById = createdById;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public String getLastModifiedById() {
return lastModifiedById;
}
public void setLastModifiedById(String lastModifiedById) {
this.lastModifiedById = lastModifiedById;
}
public Date getLastModifiedOn() {
return lastModifiedOn;
}
public void setLastModifiedOn(Date lastModifiedOn) {
this.lastModifiedOn = lastModifiedOn;
}
public Integer getVersion() {
return version;
}
private void setVersion(Integer version) {
this.version = version;
}
}
PersonLookupDTO.class
public class PersonLookupDTO extends AbstractLookupDTO<Person> {
private String name;
private Integer version;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
when create jpa query, do projection with dto and try to get the verison field, an exception throwed. i debug into the source code of hibernate, i found final Property declaredVersion = persistentClass.getDeclaredVersion(); getDeclaredVersion is null, but getVersion has value. exception details:
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [version] on this ManagedType [com.isoft.example.domain.model.Person]
at org.hibernate.metamodel.internal.AbstractManagedType.checkNotNull(AbstractManagedType.java:128)
at org.hibernate.metamodel.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:113)
at org.hibernate.query.criteria.internal.path.AbstractFromImpl.locateAttributeInternal(AbstractFromImpl.java:116)
at org.hibernate.query.criteria.internal.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:204)
at org.hibernate.query.criteria.internal.path.AbstractPathImpl.get(AbstractPathImpl.java:177)
at com.isoft.repository.hibernate.RepositoryImpl.lambda$getTupleQuery$0(RepositoryImpl.java:493)
at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:693)
at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:673)
at com.isoft.repository.hibernate.RepositoryImpl.getTupleQuery(RepositoryImpl.java:493)
at com.isoft.repository.hibernate.RepositoryImpl.search(RepositoryImpl.java:315)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
|