JPA @OneToMany注释INSERT操作

时间:2017-02-17 07:46:27

标签: java json jpa insert one-to-many

我正在实施一个书店RESTful网络应用程序。作为@OneToMany关系映射的问题,我所面临的仅仅是INSERT操作,该操作仅适用于仅包含一个Tag的列表。当我尝试使用多个元素时,它会抛出异常。

我读了很多关于同一主题的帖子,并且其他人面临着类似的问题,但他们问题的解决方案并不适合我。我也尝试使用mappedBy,但没有区别。

这是源代码和一些跟踪日志:

实体:

@Entity
@Table(name = "BOOK")
public class Book implements Serializable
{
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "BOOK_ID", nullable = false, unique = true)
    private Long id;
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "CATEGORY_ID")
    private Category category;
    @Column(name = "NAME", nullable = false)
    private String name;
    @ElementCollection
    @Column(name = "PHOTO_URLS", nullable = false)
    private List<String> photoUrls;
    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "BOOK_TAG", joinColumns = @JoinColumn(name = "BOOK_ID"), inverseJoinColumns = @JoinColumn(name = "TAG_ID"))
    private List<Tag> tags;
    @Column(name = "STATUS")
    @JsonSerialize(using = BookStatusJSONSerializer.class)
    @Enumerated(EnumType.STRING)
    private BookStatus status;

    // Getter & Setters here

}

@Entity
@Table(name = "TAG")
public class Tag implements Serializable
{
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "TAG_ID", nullable = false, unique = true)
    private Integer id;
    @Column(name = "NAME", nullable = false, unique = true)
    private String name;

    // Getter & Setters here

}

@Entity
@Table(name = "CATEGORY")
public class Category implements Serializable
{
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "CATEGORY_ID", unique = true)
    private Integer id;
    @Column(name = "NAME", unique = true)
    private String name;

    // Getter & Setters here

}

仅使用一个标记即成功插入操作:

{
    "id":1,
    "category":
    {
        "id":1,
        "name":"string1"
    },
    "name":"string1",
    "photoUrls":
    [
        "string1",
        "string2",
        "string3"
    ],
    "tags":
    [
        {
            "id":1,
            "name":"string1"
        }
    ],
    "status":"available"
}

2017-02-17 08:54:41.228 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.t.internal.TransactionImpl         : begin
2017-02-17 08:54:41.229 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.loader.Loader              : Loading entity: [com.rbc.bookstore.entities.Book#1]
2017-02-17 08:54:41.230 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.SQL                        : select book0_."book_id" as book_id1_2_2_, book0_."category_id" as category4_2_2_, book0_."name" as name2_2_2_, book0_."status" as status3_2_2_, category1_."category_id" as category1_0_0_, category1_."name" as name2_0_0_, tags2_."tag_id" as tag_id1_4_4_, tags2_."tag_id" as tag_id1_4_1_, tags2_."name" as name2_4_1_ from "book" book0_ left outer join "category" category1_ on book0_."category_id"=category1_."category_id" left outer join "tag" tags2_ on book0_."book_id"=tags2_."tag_id" where book0_."book_id"=?
2017-02-17 08:54:41.233 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.loader.Loader              : Result set row: 0
2017-02-17 08:54:41.233 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.loader.Loader              : Result row: EntityKey[com.rbc.bookstore.entities.Category#1], EntityKey[com.rbc.bookstore.entities.Tag#1], EntityKey[com.rbc.bookstore.entities.Book#1]
2017-02-17 08:54:41.234 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.loader.Loader              : Found row of collection: [com.rbc.bookstore.entities.Book.tags#1]
2017-02-17 08:54:41.235 DEBUG 11404 --- [nio-8080-exec-2] o.h.engine.internal.TwoPhaseLoad         : Resolving associations for [com.rbc.bookstore.entities.Category#1]
2017-02-17 08:54:41.235 DEBUG 11404 --- [nio-8080-exec-2] o.h.engine.internal.TwoPhaseLoad         : Done materializing entity [com.rbc.bookstore.entities.Category#1]
2017-02-17 08:54:41.235 DEBUG 11404 --- [nio-8080-exec-2] o.h.engine.internal.TwoPhaseLoad         : Resolving associations for [com.rbc.bookstore.entities.Tag#1]
2017-02-17 08:54:41.235 DEBUG 11404 --- [nio-8080-exec-2] o.h.engine.internal.TwoPhaseLoad         : Done materializing entity [com.rbc.bookstore.entities.Tag#1]
2017-02-17 08:54:41.235 DEBUG 11404 --- [nio-8080-exec-2] o.h.engine.internal.TwoPhaseLoad         : Resolving associations for [com.rbc.bookstore.entities.Book#1]
2017-02-17 08:54:41.236 DEBUG 11404 --- [nio-8080-exec-2] o.h.engine.internal.TwoPhaseLoad         : Done materializing entity [com.rbc.bookstore.entities.Book#1]
2017-02-17 08:54:41.236 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.l.internal.CollectionLoadContext   : 1 collections were found in result set for role: com.rbc.bookstore.entities.Book.tags
2017-02-17 08:54:41.236 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.l.internal.CollectionLoadContext   : Collection fully initialized: [com.rbc.bookstore.entities.Book.tags#1]
2017-02-17 08:54:41.236 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.l.internal.CollectionLoadContext   : 1 collections initialized for role: com.rbc.bookstore.entities.Book.tags
2017-02-17 08:54:41.237 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.loader.Loader              : Done entity load
2017-02-17 08:54:41.238 DEBUG 11404 --- [nio-8080-exec-2] stractLoadPlanBasedCollectionInitializer : Loading collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.238 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.SQL                        : select photourls0_."book_book_id" as book_book_1_3_0_, photourls0_."photo_urls" as photo_ur2_3_0_ from "book_photo_urls" photourls0_ where photourls0_."book_book_id"=?
2017-02-17 08:54:41.240 DEBUG 11404 --- [nio-8080-exec-2] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Preparing collection intializer : [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.240 DEBUG 11404 --- [nio-8080-exec-2] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Starting ResultSet row #0
2017-02-17 08:54:41.240 DEBUG 11404 --- [nio-8080-exec-2] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.241 DEBUG 11404 --- [nio-8080-exec-2] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Starting ResultSet row #1
2017-02-17 08:54:41.241 DEBUG 11404 --- [nio-8080-exec-2] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.241 DEBUG 11404 --- [nio-8080-exec-2] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Starting ResultSet row #2
2017-02-17 08:54:41.241 DEBUG 11404 --- [nio-8080-exec-2] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.242 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.l.internal.CollectionLoadContext   : 1 collections were found in result set for role: com.rbc.bookstore.entities.Book.photoUrls
2017-02-17 08:54:41.242 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.l.internal.CollectionLoadContext   : Collection fully initialized: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.242 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.l.internal.CollectionLoadContext   : 1 collections initialized for role: com.rbc.bookstore.entities.Book.photoUrls
2017-02-17 08:54:41.242 DEBUG 11404 --- [nio-8080-exec-2] o.h.r.j.i.ResourceRegistryStandardImpl   : HHH000387: ResultSet's statement was not registered
2017-02-17 08:54:41.242 DEBUG 11404 --- [nio-8080-exec-2] stractLoadPlanBasedCollectionInitializer : Done loading collection
2017-02-17 08:54:41.243 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.t.internal.TransactionImpl         : committing
2017-02-17 08:54:41.243 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.i.AbstractFlushingEventListener    : Processing flush-time cascades
2017-02-17 08:54:41.244 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.i.AbstractFlushingEventListener    : Dirty checking collections
2017-02-17 08:54:41.244 DEBUG 11404 --- [nio-8080-exec-2] o.hibernate.engine.spi.CollectionEntry   : Collection dirty: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.244 DEBUG 11404 --- [nio-8080-exec-2] o.hibernate.engine.spi.CollectionEntry   : Collection dirty: [com.rbc.bookstore.entities.Book.tags#1]
2017-02-17 08:54:41.245 DEBUG 11404 --- [nio-8080-exec-2] o.hibernate.engine.internal.Collections  : Collection found: [com.rbc.bookstore.entities.Book.photoUrls#1], was: [com.rbc.bookstore.entities.Book.photoUrls#1] (initialized)
2017-02-17 08:54:41.245 DEBUG 11404 --- [nio-8080-exec-2] o.hibernate.engine.internal.Collections  : Collection found: [com.rbc.bookstore.entities.Book.tags#1], was: [com.rbc.bookstore.entities.Book.tags#1] (initialized)
2017-02-17 08:54:41.245 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.i.AbstractFlushingEventListener    : Flushed: 0 insertions, 0 updates, 0 deletions to 3 objects
2017-02-17 08:54:41.245 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.i.AbstractFlushingEventListener    : Flushed: 0 (re)creations, 2 updates, 0 removals to 2 collections
2017-02-17 08:54:41.245 DEBUG 11404 --- [nio-8080-exec-2] o.hibernate.internal.util.EntityPrinter  : Listing entities:
2017-02-17 08:54:41.245 DEBUG 11404 --- [nio-8080-exec-2] o.hibernate.internal.util.EntityPrinter  : com.rbc.bookstore.entities.Category{name=string1, id=1}
2017-02-17 08:54:41.245 DEBUG 11404 --- [nio-8080-exec-2] o.hibernate.internal.util.EntityPrinter  : com.rbc.bookstore.entities.Tag{name=string1, id=1}
2017-02-17 08:54:41.245 DEBUG 11404 --- [nio-8080-exec-2] o.hibernate.internal.util.EntityPrinter  : com.rbc.bookstore.entities.Book{photoUrls=[string1, string2, string3], name=doggie, id=1, category=com.rbc.bookstore.entities.Category#1, status=AVAILABLE, tags=[com.rbc.bookstore.entities.Tag#1]}
2017-02-17 08:54:41.246 DEBUG 11404 --- [nio-8080-exec-2] o.h.p.c.AbstractCollectionPersister      : Deleting collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.246 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.SQL                        : delete from "book_photo_urls" where "book_book_id"=?
2017-02-17 08:54:41.247 DEBUG 11404 --- [nio-8080-exec-2] o.h.p.c.AbstractCollectionPersister      : Done deleting collection
2017-02-17 08:54:41.247 DEBUG 11404 --- [nio-8080-exec-2] o.h.p.c.AbstractCollectionPersister      : Inserting collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 08:54:41.248 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.SQL                        : insert into "book_photo_urls" ("book_book_id", "photo_urls") values (?, ?)
2017-02-17 08:54:41.248 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.SQL                        : insert into "book_photo_urls" ("book_book_id", "photo_urls") values (?, ?)
2017-02-17 08:54:41.249 DEBUG 11404 --- [nio-8080-exec-2] org.hibernate.SQL                        : insert into "book_photo_urls" ("book_book_id", "photo_urls") values (?, ?)
2017-02-17 08:54:41.250 DEBUG 11404 --- [nio-8080-exec-2] o.h.p.c.AbstractCollectionPersister      : Done inserting collection: 3 rows inserted
2017-02-17 08:54:41.250 DEBUG 11404 --- [nio-8080-exec-2] o.h.p.c.AbstractCollectionPersister      : Deleting rows of collection: [com.rbc.bookstore.entities.Book.tags#1]
2017-02-17 08:54:41.251 DEBUG 11404 --- [nio-8080-exec-2] o.h.p.c.AbstractCollectionPersister      : No rows to delete
2017-02-17 08:54:41.251 DEBUG 11404 --- [nio-8080-exec-2] o.h.p.c.AbstractCollectionPersister      : Inserting rows of collection: [com.rbc.bookstore.entities.Book.tags#1]
2017-02-17 08:54:41.251 DEBUG 11404 --- [nio-8080-exec-2] o.h.p.c.AbstractCollectionPersister      : Done inserting rows: 0 inserted
2017-02-17 08:54:41.253 DEBUG 11404 --- [nio-8080-exec-2] o.h.e.jdbc.internal.JdbcCoordinatorImpl  : HHH000420: Closing un-released batch

......这里是一个带有两个标签的不成功的插入操作:

{
    "id":1,
    "category":
    {
        "id":1,
        "name":"string1"
    },
    "name":"string1",
    "photoUrls":
    [
        "string1",
        "string2",
        "string3"
    ],
    "tags":
    [
        {
            "id":1,
            "name":"string1"
        },
        {
            "id":2,
            "name":"string2"
        }
    ],
    "status":"available"
}

2017-02-17 09:31:03.662 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.t.internal.TransactionImpl         : begin
2017-02-17 09:31:03.664 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.loader.Loader              : Loading entity: [com.rbc.bookstore.entities.Book#1]
2017-02-17 09:31:03.665 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.SQL                        : select book0_."book_id" as book_id1_2_2_, book0_."category_id" as category4_2_2_, book0_."name" as name2_2_2_, book0_."status" as status3_2_2_, category1_."category_id" as category1_0_0_, category1_."name" as name2_0_0_, tags2_."tag_id" as tag_id1_4_4_, tags2_."tag_id" as tag_id1_4_1_, tags2_."name" as name2_4_1_ from "book" book0_ left outer join "category" category1_ on book0_."category_id"=category1_."category_id" left outer join "tag" tags2_ on book0_."book_id"=tags2_."tag_id" where book0_."book_id"=?
2017-02-17 09:31:03.667 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.loader.Loader              : Result set row: 0
2017-02-17 09:31:03.667 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.loader.Loader              : Result row: EntityKey[com.rbc.bookstore.entities.Category#1], EntityKey[com.rbc.bookstore.entities.Tag#1], EntityKey[com.rbc.bookstore.entities.Book#1]
2017-02-17 09:31:03.668 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.loader.Loader              : Found row of collection: [com.rbc.bookstore.entities.Book.tags#1]
2017-02-17 09:31:03.668 DEBUG 11404 --- [nio-8080-exec-5] o.h.engine.internal.TwoPhaseLoad         : Resolving associations for [com.rbc.bookstore.entities.Category#1]
2017-02-17 09:31:03.668 DEBUG 11404 --- [nio-8080-exec-5] o.h.engine.internal.TwoPhaseLoad         : Done materializing entity [com.rbc.bookstore.entities.Category#1]
2017-02-17 09:31:03.668 DEBUG 11404 --- [nio-8080-exec-5] o.h.engine.internal.TwoPhaseLoad         : Resolving associations for [com.rbc.bookstore.entities.Tag#1]
2017-02-17 09:31:03.669 DEBUG 11404 --- [nio-8080-exec-5] o.h.engine.internal.TwoPhaseLoad         : Done materializing entity [com.rbc.bookstore.entities.Tag#1]
2017-02-17 09:31:03.669 DEBUG 11404 --- [nio-8080-exec-5] o.h.engine.internal.TwoPhaseLoad         : Resolving associations for [com.rbc.bookstore.entities.Book#1]
2017-02-17 09:31:03.669 DEBUG 11404 --- [nio-8080-exec-5] o.h.engine.internal.TwoPhaseLoad         : Done materializing entity [com.rbc.bookstore.entities.Book#1]
2017-02-17 09:31:03.669 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.l.internal.CollectionLoadContext   : 1 collections were found in result set for role: com.rbc.bookstore.entities.Book.tags
2017-02-17 09:31:03.670 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.l.internal.CollectionLoadContext   : Collection fully initialized: [com.rbc.bookstore.entities.Book.tags#1]
2017-02-17 09:31:03.670 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.l.internal.CollectionLoadContext   : 1 collections initialized for role: com.rbc.bookstore.entities.Book.tags
2017-02-17 09:31:03.670 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.loader.Loader              : Done entity load
2017-02-17 09:31:03.671 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.loader.Loader              : Loading entity: [com.rbc.bookstore.entities.Tag#2]
2017-02-17 09:31:03.671 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.SQL                        : select tag0_."tag_id" as tag_id1_4_0_, tag0_."name" as name2_4_0_ from "tag" tag0_ where tag0_."tag_id"=?
2017-02-17 09:31:03.673 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.loader.Loader              : Done entity load
2017-02-17 09:31:03.673 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.i.AbstractSaveEventListener        : Generated identifier: 2, using strategy: org.hibernate.id.Assigned
2017-02-17 09:31:03.674 DEBUG 11404 --- [nio-8080-exec-5] stractLoadPlanBasedCollectionInitializer : Loading collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 09:31:03.674 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.SQL                        : select photourls0_."book_book_id" as book_book_1_3_0_, photourls0_."photo_urls" as photo_ur2_3_0_ from "book_photo_urls" photourls0_ where photourls0_."book_book_id"=?
2017-02-17 09:31:03.675 DEBUG 11404 --- [nio-8080-exec-5] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Preparing collection intializer : [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 09:31:03.676 DEBUG 11404 --- [nio-8080-exec-5] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Starting ResultSet row #0
2017-02-17 09:31:03.676 DEBUG 11404 --- [nio-8080-exec-5] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 09:31:03.676 DEBUG 11404 --- [nio-8080-exec-5] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Starting ResultSet row #1
2017-02-17 09:31:03.676 DEBUG 11404 --- [nio-8080-exec-5] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 09:31:03.676 DEBUG 11404 --- [nio-8080-exec-5] o.h.l.p.e.p.i.ResultSetProcessorImpl     : Starting ResultSet row #2
2017-02-17 09:31:03.676 DEBUG 11404 --- [nio-8080-exec-5] e.p.i.CollectionReferenceInitializerImpl : Found row of collection: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 09:31:03.676 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.l.internal.CollectionLoadContext   : 1 collections were found in result set for role: com.rbc.bookstore.entities.Book.photoUrls
2017-02-17 09:31:03.677 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.l.internal.CollectionLoadContext   : Collection fully initialized: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 09:31:03.677 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.l.internal.CollectionLoadContext   : 1 collections initialized for role: com.rbc.bookstore.entities.Book.photoUrls
2017-02-17 09:31:03.677 DEBUG 11404 --- [nio-8080-exec-5] o.h.r.j.i.ResourceRegistryStandardImpl   : HHH000387: ResultSet's statement was not registered
2017-02-17 09:31:03.677 DEBUG 11404 --- [nio-8080-exec-5] stractLoadPlanBasedCollectionInitializer : Done loading collection
2017-02-17 09:31:03.677 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.t.internal.TransactionImpl         : committing
2017-02-17 09:31:03.678 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.i.AbstractFlushingEventListener    : Processing flush-time cascades
2017-02-17 09:31:03.678 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.i.AbstractFlushingEventListener    : Dirty checking collections
2017-02-17 09:31:03.678 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.engine.spi.CollectionEntry   : Collection dirty: [com.rbc.bookstore.entities.Book.photoUrls#1]
2017-02-17 09:31:03.679 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.engine.spi.CollectionEntry   : Collection dirty: [com.rbc.bookstore.entities.Book.tags#1]
2017-02-17 09:31:03.679 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.engine.internal.Collections  : Collection found: [com.rbc.bookstore.entities.Book.photoUrls#1], was: [com.rbc.bookstore.entities.Book.photoUrls#1] (initialized)
2017-02-17 09:31:03.679 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.engine.internal.Collections  : Collection found: [com.rbc.bookstore.entities.Book.tags#1], was: [com.rbc.bookstore.entities.Book.tags#1] (initialized)
2017-02-17 09:31:03.680 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.i.AbstractFlushingEventListener    : Flushed: 1 insertions, 0 updates, 0 deletions to 4 objects
2017-02-17 09:31:03.680 DEBUG 11404 --- [nio-8080-exec-5] o.h.e.i.AbstractFlushingEventListener    : Flushed: 0 (re)creations, 2 updates, 0 removals to 2 collections
2017-02-17 09:31:03.680 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.internal.util.EntityPrinter  : Listing entities:
2017-02-17 09:31:03.680 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.internal.util.EntityPrinter  : com.rbc.bookstore.entities.Category{name=string1, id=1}
2017-02-17 09:31:03.680 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.internal.util.EntityPrinter  : com.rbc.bookstore.entities.Tag{name=string1, id=1}
2017-02-17 09:31:03.681 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.internal.util.EntityPrinter  : com.rbc.bookstore.entities.Book{photoUrls=[string1, string2, string3], name=doggie, id=1, category=com.rbc.bookstore.entities.Category#1, status=AVAILABLE, tags=[com.rbc.bookstore.entities.Tag#1, com.rbc.bookstore.entities.Tag#2]}
2017-02-17 09:31:03.681 DEBUG 11404 --- [nio-8080-exec-5] o.hibernate.internal.util.EntityPrinter  : com.rbc.bookstore.entities.Tag{name=string2, id=2}
2017-02-17 09:31:03.681 DEBUG 11404 --- [nio-8080-exec-5] org.hibernate.SQL                        : insert into "tag" ("name", "tag_id") values (?, ?)
2017-02-17 09:31:03.689 DEBUG 11404 --- [nio-8080-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : could not execute statement [n/a]

java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: foreign key no parent; "FK54oiqofxlntc22v49amlljiw" table: "tag"
    .....

以下是数据库关系的UML图: enter image description here

0 个答案:

没有答案