-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Annotations : Use @Any / CascadeType.ALL
PostPosted: Wed Mar 25, 2009 10:48 am 
Newbie

Joined: Wed Mar 25, 2009 10:11 am
Posts: 1
Hibernate Core version: 3.3.1 GA
Hibernate Annotation version: 3.4.0 GA

Hello,

I would like to use CascadeType.ALL or CascadeType.PERSIST for the moment with @Any annotation.

This is what I have in my Entity :
Please note that I create MyBook directly in getMyObject() for test only :). Of course, MyBook and MyDvd implement MyObject's interface.
Code:
MyEntity{
...

    @Any(fetch=FetchType.EAGER , metaColumn = @Column(name = "ITEM_TYPE"))
    @AnyMetaDef(idType = "long", metaType = "string",
            metaValues = {
             @MetaValue(targetEntity = MyBook.class, value = "B"),
             @MetaValue(targetEntity = MyDvd.class, value = "D"),
       })
    @JoinColumn(name="ITEM_ID")
    @Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN })
   public MyObject getMyObject() {
      MyBook book = new MyBook();
      book.setBookValue("My Book value!!");
      return book;
   }

...
}


To persist I do (I use EntityManager):
Code:
//Here MyEntity is created and ready for persist
entityManager.persist(myEntity)


hibernate trace in debug mode:
Code:
15:33:52,171 INFO  [STDOUT] Hibernate:
    insert
    into
        MyBook
        (id, bookValue, name, version)
    values
        (null, ?, ?, ?)
15:33:52,171 INFO  [STDOUT] Hibernate:
    call identity()
15:33:52,171 INFO  [STDOUT] Hibernate:
    insert
    into
        MyEntity
        (id, code, ITEM_TYPE, ITEM_ID)
    values
        (null, ?, ?, ?)
15:33:52,171 INFO  [STDOUT] Hibernate:
    call identity()
15:33:52,203 INFO  [STDOUT] Hibernate:
    insert
    into
        MyBook
        (id, bookValue, name, version)
    values
        (null, ?, ?, ?)
15:33:52,203 INFO  [STDOUT] Hibernate:
    call identity()
15:33:52,218 INFO  [STDOUT] Hibernate:
    update
        MyEntity
    set
        code=?,
        ITEM_TYPE=?,
        ITEM_ID=?
    where
        id=?


I got exception :
Code:
ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.package.entity.MyBook


Do you have any suggestion? Thank you all!
Max


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.