JPA@OneToMany获取空

JPA@OneToMany获取空,jpa,one-to-many,Jpa,One To Many,桌子 我能够检索应用程序用户OnetoOne角色组的结果,但角色组oneToMany ROLE状态为空。我使用org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean映射对象 Rolstate是空的,显然我错过了一些东西,任何帮助都将不胜感激。我想,您错过了地图的反面…请尝试以下内容: @OneToMany(mappedBy="roleId", fetch=FetchType.EAGER) @JoinCo

桌子

我能够检索应用程序用户OnetoOne角色组的结果,但角色组oneToMany ROLE状态为空。我使用org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean映射对象


Rolstate是空的,显然我错过了一些东西,任何帮助都将不胜感激。

我想,您错过了地图的反面…请尝试以下内容:

@OneToMany(mappedBy="roleId", fetch=FetchType.EAGER)
@JoinColumn(name="ROLE_ID")
Set<RoleState> roleState;
 @Entity
    @Table(name = "APP_USER")
    public class AppUser implements Serializable{

        private static final long serialVersionUID = 1L;

        @Column(name = "ROLE_GROUP_ID")
        private Integer roleGroupIdAppuser;

        @Id
        @Column(name="APP_USER_ID")
        Integer appUserID;

        @Column(name = "USERNAME")
        private String userName;

        @OneToOne(fetch=FetchType.EAGER)
        @JoinColumn(name="ROLE_GROUP_ID",insertable=false,updatable=false)
        private RoleGroup roleGroup;    


    @Entity
    @Table(name = "ROLE_GROUP")
    public class RoleGroup implements Serializable{

        @Id
        @Column(name="ROLE_GROUP_ID")
        private Integer roleGroupId;

        @Column(name="ROLE_ID")
        private Integer roleID;

        @Column(name="APP_GROUP_ID")
        private Integer appGroupId;

        @OneToMany(fetch=FetchType.EAGER)
        @JoinColumn(name="ROLE_ID")
        Set<RoleState> roleState;

        public Integer getRoleGroupId() {
            return roleGroupId;
        }    

    @Entity
    @Table(name = "ROLE_STATE")
    public class RoleState implements Serializable {

        private static final long serialVersionUID = 1L;

        /*@Embeddable
        public static class Pk implements Serializable {

            @Column(name = "ROLE_ID", nullable = false, updatable = false)
            private Integer roleId;

            @Column(name = "STATE_ID", nullable = false, updatable = false)
            private Integer stateId;

            @Column(name = "TARGET_STATE_ID", nullable = false, updatable = false)
            private int targetStateID;
        }

         @EmbeddedId
         private Pk pk;*/

        @Id
        @Column(name = "ROLE_ID")
        private Integer roleId;

        @Id
        @Basic(optional = true)
        @Column(name = "STATE_ID")
        private Integer stateId;

        @Id
        @Basic(optional = true)
        @Column(name = "TARGET_STATE_ID")
        private Integer targetStateID;

        @OneToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "STATE_ID",insertable=false,updatable=false)
        State state;

    AppUser appUser=(AppUser)currentSession().createQuery("from AppUser where       userName=:userNamel").setParameter("userNamel", userNamel.toUpperCase()).list().get(0);

            System.out.println(appUser.getRoleGroup().getRoleID());
            Set<RoleState> roleState=appUser.getRoleGroup().getRoleState();
            for(RoleState role:roleState){
                System.out.println(role.getState().getName());
            }

            System.out.println(appUser.getUserName());
@OneToMany(mappedBy="roleId", fetch=FetchType.EAGER)
@JoinColumn(name="ROLE_ID")
Set<RoleState> roleState;