简体   繁体   中英

Basic attribute type should not be IDao - intellij message

I am receiving the following message in my Entity object ?

Basic attribute type should not be IDao

Where it is being used like this :

@Entity
@Table
public final class MyEnity {

    @Resource(name = "Dao")
    private IDao dao;

I know the name is bad, but what is the problem with injecting my Dao(annotated with repository) into my Domain object that is annotated as a hibernate entity ? And IDao is an interface implemented by Dao class ...

IDao seems to be a processing element getting injected into an entity and you don't intend to persist it. If so, you should mark it as transient so that the ORM will ignore it during CRUD operations on the entity.

@Resource(name = "Dao")
private transient IDao dao;

BTW, I don't see your entity to be @Configurable . How do you plan to get dao injected into it? The ORM is going to create a new object of type MyEntity using the default constrcutor and call the setters to set the values from the database. Your IDao dao will not get injected as such an instance is not a spring-managed bean. You have to mark MyEntity as @Configurable to make it spring managed so that instances created using new operator will get the resource injected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM