Java Hibernate实体类获取程序在设置值后返回null

Java Hibernate实体类获取程序在设置值后返回null,java,hibernate,hashmap,dropwizard,Java,Hibernate,Hashmap,Dropwizard,我有一个hibernate实体类 public class MyComplexClass implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; String name; int number; @ElementC

我有一个hibernate实体类

public class MyComplexClass implements  Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;

    String name;
    int number;
    @ElementCollection
    Map<String,String> myMap;

    @ManyToOne
    Simple simple;

    public MyComplexClass(String name, int number, Map<String,String> myMap) {
        this.name = name;
        this.port = number;
        this.myMap = myMap;
    }

    public MyComplexClass() {
        // TODO Auto-generated constructor stub
    }

    public void setName(String name) {
        this.name = name;

    }

    public String getName() {
        return name;
    }

    public void setNumber(int number) {
        this.port = number;
    }

    public int getPort() {
        return port;
    }

    public void setMyMap(Map<String,String> myMap) {
        this.myMap = myMap;
    }

    public Map<String,String> getMyMap() {
        return this.myMap;
    }


    public Simple getSimple() {
        return this.simple;
    }
。它返回一个空指针。调试时,我看到
simple.getMyComplexClass()
本身为空

为什么它不返回设置的值?它是与数据库相关还是与内存缓存相关


在数据库中,我确实在MyComplex类表的外键列中看到空值,这就是原因吗?

您必须向我们展示更多代码。例如,getter和setteradded getter和setters以及
simple.setMyComplexClass
?完成后,添加了必要的getter
()
simple.getMyComplexClass.get(0.getMyMap
    @Entity
    @Table(name = "Simple")


    public class Simple  implements Comparable<Simple>, Serializable {
    @JsonProperty
    @OneToMany(mappedBy="simple",fetch = FetchType.EAGER,cascade = CascadeType.ALL)
    List<MyComplexClass> myComplexClass;

    public void setMyComplexClass(List<MyComplexClass> myComplexClass) {
        this.myComplexClass = myComplexClass;
    }

    public List<MyComplexClass> getMyComplexClass() {
        return this.myComplexClass;
    }
Map<String, String> myMap = new HashMap<String,String>();
myMap.put("value","value");
MyComplexClass myComplexClass = new MyComplexclass("a", 123, myMap)
List<MyComplexClass> myComplexClassList = new ArrayList<MyComplexClass>();
myComplexClassList.add(myComplexClassList)
simple.setMyComplexClass(myComplexClassList);
// save to the database
dao.save(simple);
Simple simple = dao.getSimple(simple.id);
`simple.getMyComplexClass.get(0).getMyMap.get("value")`