Results 1 to 4 of 4
  1. #1
    scibi92 is offline Member
    Join Date
    Dec 2014
    Posts
    2
    Rep Power
    0

    Default Hibernate-Cannot Save The Child

    Hello
    I have a problem -I jave many to one relation in database and I can't save many side.
    I was trying to found out solution,but I didn't find...
    Java Code:
    //OneToMany
    @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="owner") 
       @Column(nullable = false)
       private Set<Contact> contacts;
    //ManyToOne
    @ManyToOne(fetch=FetchType.EAGER)
       @JoinColumn(name="user_id", nullable = false )
       private User owner;
     
     
    //Attempt save
    user.addContact(contact);
    userDAO.save(user);
    After this table Contact is still null
    I was trying also

    Java Code:
    contact.setOwner(user);
    contactDAO.save(contact);

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Hibernate-Cannot Save The Child

    a) the @Column annotation on the set of contacts makes no sense - it is not even a column
    b) 'Contact is still null' also makes no sense. What Contact is still null? Are you really talking about the user.contacts set still being null?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    scibi92 is offline Member
    Join Date
    Dec 2014
    Posts
    2
    Rep Power
    0

    Default Re: Hibernate-Cannot Save The Child

    Quote Originally Posted by gimbal2 View Post
    a) the @Column annotation on the set of contacts makes no sense - it is not even a column
    b) 'Contact is still null' also makes no sense. What Contact is still null? Are you really talking about the user.contacts set still being null?
    It was wrong expression,I mean after atempt of session save hibernate doesn't insert into table of database,it's empty

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Hibernate-Cannot Save The Child

    Yeah well you're doing something wrong (and I won't be able to say what since you only post a tiny snippet) and it most likely stems from not knowing properly how JPA works. Did you realize you're using JPA and not Hibernate directly?

    I recommend giving the book Pro JPA 2 a read.

    Pro JPA 2 (Expert&#39;s Voice in Java): Mike Keith, Merrick Schincariol: 9781430249269: Amazon.com: Books
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. How can i save the data Internally(auto save)
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2010, 08:31 PM
  2. Replies: 2
    Last Post: 06-30-2007, 03:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •