facebook

hibernate, one to many, persist parent, no children.

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #273920 Reply

    CyTG
    Member

    If the subj had been long enough
    hibernate, one to many, persist parent, parent ok, children not ok
    Wich pretty much sums it up.
    I do a parent, then i do 10 children, add the children to the parent (as a set). do a save on the parent, the paret gets persisted but the children do not.
    I use MyEclipse hibernate perspective to reverse the tables wich look like this

    create table test2(
    col1 varchar2(20) not null,
    col2 varchar2(20) null,
    col3 varchar2(20) null,
    col4 varchar2(20) null,
    constraint test2pk primary key(col1)
    );

    create table test3(
    col1 varchar2(20) not null,
    col2 varchar2(20) not null,
    col3 varchar2(20) null,
    constraint test3pk primary key(col1),
    constraint test3fktest2 foreign key(col2) references test2(col1)
    );

    Then execute this code from within an ejb3

    public void doSomethingElse(){
    Test2DAO dao = new Test2DAO();
    Session session = dao.getSession();
    int childpk = 0;
    for(int i=0;i<1000;i++){
    Transaction tx = session.beginTransaction();
    tx.begin();
    Test2 test2 = new Test2();
    test2.setCol1(“”+i);
    test2.setCol4(“column4_”+i);
    Set set = new HashSet();
    for(int j=0;j<10;j++){
    Test3 test3 = new Test3();
    test3.setCol1(“”+childpk++);
    test3.setCol3(“test3col3bbq”);
    test3.setTest2(test2);
    set.add(test3);
    }
    test2.setTest3s(set);
    session.save(test2);
    tx.commit();
    }
    }

    So .. im being told that this is not doable ? and that i have to persist these objects manually.. but looking at documentation and other resources (like this http://forum.hibernate.org/viewtopic.php?t=956859) .. im getting the impression that this should be possible on some level .. i understand hibernate doesnt do one to one, but this is one to many!

    Ideas ? or am i missing something very very obvious ?? (wouldnt be the first time and i hate it when that happens!!!!!!!)

    Best regards.

    #273921 Reply

    CyTG
    Member

    sorry, wasnt prepared for the elite html formatting skills ..
    here
    http://pastebin.com/m68001514

    #273923 Reply

    CyTG
    Member

    http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-transitive

    i was reading this too and I read it like ; value types, wich should work out of the box like this, is exactly what im doing, freshly inserts to the database, and entities is something that is allready present and i wich case you need to supply the cascade option to the mapping xmls.
    Well i did that anyway, just in case my comprehension skills leaves something to be desired.
    But the result is the same … that is no result at all ;).
    My xmls are here
    http://pastebin.com/m27713ae5

    #273924 Reply

    CyTG
    Member

    well well well … it would seem that altering the cascade value from persist to all did the trick !!! why god why ??

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: hibernate, one to many, persist parent, no children.

You must be logged in to post in the forum log in