# Hibernate not recognize properties defined in Interface

**URL:** <https://discourse.hibernate.org/t/hibernate-not-recognize-properties-defined-in-interface/9930>\
**Category:** Hibernate ORM\
**Created:** [July 11, 2024, 3:27am UTC](https://discourse.hibernate.org/t/hibernate-not-recognize-properties-defined-in-interface/9930 "2024-07-11T03:27:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lsong98sh](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@lsong98sh](https://discourse.hibernate.org/u/lsong98sh)\
**Post date:** [July 11, 2024, 3:27am UTC](https://discourse.hibernate.org/t/hibernate-not-recognize-properties-defined-in-interface/9930/1 "2024-07-11T03:27:22Z")

</div>

code below:

```auto
public interface IBaseEntity {

	String getfId();
	
	void setfId(String fId);
	
	Map<String, Object> getFeatureMap();

	default void setFeatureValue(String key, Object value) {
		getFeatureMap().put(key, value);
	}

	default Object getFeatureValue(String key) {
		return getFeatureMap().get(key);
	}
	
}

public interface ITimeMark extends IBaseEntity {
    final String fCreateTime = "f_create_time";
    final String fModifyTime = "f_modify_time";

	@Column(name="f_create_time")
	@Access(AccessType.PROPERTY)
	default Date getfCreateTime() {
		return (Date)getFeatureMap().get(ITimeMark.fCreateTime);
	}

	default void setfCreateTime(Date fCreateTime) {
		this.getFeatureMap().put(ITimeMark.fCreateTime, fCreateTime);
	}

	@Column(name="f_modify_time")
	@Access(AccessType.PROPERTY)
	default Date getfModifyTime() {
		return (Date)getFeatureMap().get(ITimeMark.fModifyTime);
	}

	default void setfModifyTime(Date fModifyTime) {
		this.getFeatureMap().put(ITimeMark.fModifyTime, fModifyTime);
	}
	
}

@MappedSuperclass
public class BaseEntity implements IBaseEntity, Serializable {

	private static final long serialVersionUID = 1L;

	@Id()
	@Column(name="f_id", length=32)
	@Access(AccessType.PROPERTY)
	protected String fId;
	
	public String getfId() {
		if(!StringUtils.hasText(fId)) {
			fId = IDGenerate.generate();
		}
		return fId;
	}

	public void setfId(String fId) {
		if(StringUtils.hasText(fId)) {
			this.fId = fId;
		}
	}

	@Transient
	private Map<String, Object> featureMap = null;
	
	public Map<String, Object> getFeatureMap() {
		if(featureMap == null) {
			featureMap = new HashMap<String, Object>();
		}
		return featureMap;
	}
}
@Entity
public class TestModel extends BaseEntity implements ITimeMark {

}

```

Column 【createTime】 and 【modifyTime】 not generated。  
hibernate version 6.3.1

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [July 11, 2024, 10:22am UTC](https://discourse.hibernate.org/t/hibernate-not-recognize-properties-defined-in-interface/9930/2 "2024-07-11T10:22:23Z")

</div>

You can’t have persistent attribute mappings in interfaces. Move these mappings into a `@MappedSuperclass`.

---

<div class="post-metadata">

**Author:** ![lsong98sh](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@lsong98sh](https://discourse.hibernate.org/u/lsong98sh)\
**Post date:** [July 11, 2024, 12:32pm UTC](https://discourse.hibernate.org/t/hibernate-not-recognize-properties-defined-in-interface/9930/3 "2024-07-11T12:32:54Z")

</div>

The java class can’t be inherit from two or more superclass。  
I’m think of doing something after the annotation process， and add these fields in interface。  
or  
Will @MappedSuperInterface be supported in the future release？

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [July 11, 2024, 3:16pm UTC](https://discourse.hibernate.org/t/hibernate-not-recognize-properties-defined-in-interface/9930/4 "2024-07-11T15:16:30Z")

</div>

> [@lsong98sh](#):
>
> Will @MappedSuperInterface be supported in the future release？

No, and you IMO shouldn’t try to use SPIs to force this model onto Hibernate ORM. One possible way forward is to create a special subtype of `BaseEntity` which implement the `ITimeMark` interface and adds these persistent attributes e.g.

```java
public interface ITimeMark extends IBaseEntity {
	final String fCreateTime = "f_create_time";
	final String fModifyTime = "f_modify_time";

	Date getfCreateTime();
	void setfCreateTime(Date fCreateTime);
	Date getfModifyTime();
	void setfModifyTime(Date fModifyTime);
}
@MappedSuperclass
public class TimeMarkBaseEntity extends BaseEntity implements ITimeMark {

	@Override
	@Column(name="f_create_time")
	@Access(AccessType.PROPERTY)
	public Date getfCreateTime() {
		return (Date)getFeatureMap().get(ITimeMark.fCreateTime);
	}

	@Override
	public void setfCreateTime(Date fCreateTime) {
		this.getFeatureMap().put(ITimeMark.fCreateTime, fCreateTime);
	}

	@Override
	@Column(name="f_modify_time")
	@Access(AccessType.PROPERTY)
	public Date getfModifyTime() {
		return (Date)getFeatureMap().get(ITimeMark.fModifyTime);
	}

	@Override
	public void setfModifyTime(Date fModifyTime) {
		this.getFeatureMap().put(ITimeMark.fModifyTime, fModifyTime);
	}
}

@Entity
public class TestModel extends TimeMarkBaseEntity {
}

```
