Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.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
Java 不带joincolumn/jointable的Hibbernate映射映射_Java_Hibernate_Dictionary_Mapping_Persistence - Fatal编程技术网

Java 不带joincolumn/jointable的Hibbernate映射映射

Java 不带joincolumn/jointable的Hibbernate映射映射,java,hibernate,dictionary,mapping,persistence,Java,Hibernate,Dictionary,Mapping,Persistence,尝试Hibernate 4.3文档“7.2.2.2.Maps”中的示例,其中我有两个实体: @Entity public class Order { @Id @GeneratedValue private Integer id; String number; @ManyToOne private Customer customer; //getters/setters } @Entity public class Customer

尝试Hibernate 4.3文档“7.2.2.2.Maps”中的示例,其中我有两个实体:

@Entity
public class Order {

    @Id
    @GeneratedValue
    private Integer id;

    String number;

    @ManyToOne
    private Customer customer;

    //getters/setters
}

@Entity
public class Customer {
    @Id
    @GeneratedValue
    private Integer id;

    @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL)
    @MapKey(name = "number")
    private Map<String, Order> orders;

    //getters/setters
}

怎么了?

您没有在任何地方初始化订单的
number
属性,因为type
String
的默认值是
null
,因此您在db中得到了一个空值。

我正在重新考虑这个功能,我错了。如何正确地说。此功能用于加载贴图,但不用于自动填充属性。
session.beginTransaction();
Map<String, Order> map = new HashMap<>();
map.put("0", new Order());
map.put("1", new Order());
map.put("2", new Order());
map.put("3", new Order());
Customer customer = new Customer();
customer.setOrders(map);
session.save(customer);
session.getTransaction().commit();