简体   繁体   English

如何将包含另一个实体对象的实体对象持久化到数据库?

[英]How to persist Entity object which contains another Entity Objects to the database?

I have a problem with my function which is supposed to save data to database, function creates a new object which includes other objects. 我的函数存在问题,该函数应该将数据保存到数据库,函数会创建一个包含其他对象的新对象。 I am able to save and fetch objects which contain only primitive data types and Strings to Database , so the database and system works in this case. 我能够将仅包含原始数据类型和字符串的对象保存并提取到Database,因此在这种情况下,数据库和系统都可以使用。 I am using JavaEE and EntityManager (persist). 我正在使用JavaEE和EntityManager(持久性)。 Any help? 有什么帮助吗?

You can define a cascade type on the parent entity. 您可以在父实体上定义级联类型。 Have a look on the Java EE tutorial ( http://docs.oracle.com/javaee/6/tutorial/doc/bnbqa.html#bnbqm ) 看看Java EE教程( http://docs.oracle.com/javaee/6/tutorial/doc/bnbqa.html#bnbqm

see the principal below 见下面的校长

@Entity
public class Customer {
    @OneToMany(cascade=CascadeType.ALL, mappedBy="customer")
    public Set<Order> getOrders() { 
        return orders; 
    }
    ...
}

@Entity
public class Order {
    @OneToOne
    Customer customer;
    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何持久化仅包含集合和ID的实体? - How to persist an Entity that only contains a collection and an ID? 如何在不将第一个实体插入Entity Framework C#中的数据库的情况下将实体ID分配给另一个实体? - How to assign entity Id to another entity without inserting first entity into database in Entity Framework, C#? 如何在 Kotlin 中使用包含一些实体表的 @Embedded 表和同样包含实体的 @Embedded 表构建 RoomDB? - How to build RoomDB in Kotlin with @Embedded table which contains some entity tables and the same @Embedded table, which contains entity too? 如何命名仅显示数据库实体一部分的类 - How to name a class which only shows a part of a database entity 您如何描述一个数据库实体,它可以是费用还是收益? - How would you describe a database entity which can be an expense or a gain? 如果我的实体与另一个实体有(0-1):1的关系,我将如何在数据库中对其进行建模? - If my entity has a (0-1):1 relation to another entity, how would I model that in the database? 实体框架 - 从数据库刷新对象 - Entity Framework - refresh objects from database 如何使用LINQ to Entity中的包含功能 - How to use feature like Contains in LINQ to Entity 免费托管 ac# 后端解决方案(包含实体框架) - Host a c# backend solution (which contains entity framework) for free 如何查看JHipster实体数据库 - How to view JHipster Entity Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM