Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaHibernate中,您可以拥有一个不是实体的模型吗?_Java_Spring_Hibernate_Model - Fatal编程技术网

在JavaHibernate中,您可以拥有一个不是实体的模型吗?

在JavaHibernate中,您可以拥有一个不是实体的模型吗?,java,spring,hibernate,model,Java,Spring,Hibernate,Model,当我试图编译org.springframework.beans.factory.BeanCreationException时,我遇到了这个错误:创建名为“entityManagerFactory”的bean时出错,该bean在类路径资源[org/springframework/boot/autoconfigure/orm/jpa/hibernatejbaconfiguration.class]中定义:初始化方法调用失败;嵌套异常为org.hibernate.AnnotationException

当我试图编译
org.springframework.beans.factory.BeanCreationException时,我遇到了这个错误:创建名为“entityManagerFactory”的bean时出错,该bean在类路径资源[org/springframework/boot/autoconfigure/orm/jpa/hibernatejbaconfiguration.class]中定义:初始化方法调用失败;嵌套异常为org.hibernate.AnnotationException:com.core.model.Team.members[com.core.model.User]

我的模型称为User,它用于组合其他两个模型,一个从keydove获取数据,另一个从Postgres获取数据。此表未使用@entity,因为它未附加到表。有什么我不知道的吗

这是密码

@Data
public class User {

   @NonNull
    private KeycloakUser keycloakUser;
 
    private OtherUser otherUser;

    public User(@NonNull KeycloakUser keycloakUser, @NonNull OtherUser otherUser) {
        this.keycloakUser = keycloakUser;
        this.otherUser = otherUser;
    }
}

您必须具有非实体的模型。模型类必须与实体分开

class User {
             
  private KeycloakUser keycloakUser;
             
  private OtherUser otherUser;
             
}

User user = new User();
userService.saveUser(user);

// UserService

void saveUser(User user) {
    UserEntity userEntity = userMapper.toUserEntity(user.getOtherUser());
    userRespository.save(userEntity);

    CreateUserRequest request = userMapper.toCreateUserRequest(user.getKeycloakUser());
    keyCloakClient.createUser(request);
}

// UserMapper

UserEntity toUserEntity(OtherUser user) {
    UserEntity result = new UserEntity();
    result.setName(user.getName());

    return resut;
}
   

我不太明白。错误非常直接:是否希望使用JPA将
com.core.model.User
Team.members集合中的
s持久化到数据库中?如果是,请使用
@实体
注释
用户
。如果没有,请组成
团队。成员
@Transient
并去除JPA抱怨的
@OneToMany
。如果我有点误解了这个问题,请解释你所说的“非实体模型”是什么意思。@crizzis谢谢,你提出的问题帮助我集中精力在哪里找到问题。我还没找到,但至少我有更好的主意去哪里找