-->
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.  [ 2 posts ] 
Author Message
 Post subject: help w/ simple joining of 2 table with annotations
PostPosted: Thu Jan 07, 2010 6:38 pm 
Newbie

Joined: Thu Jan 07, 2010 6:08 pm
Posts: 2
Hi all, been combing the examples/books and getting stuck on something simple, but can't find something simple that meets my needs. please help if you could.

I am trying to get my
entityManager.persist( mailboxBean );
to work and it is getting an issue where i think the join
between 2 tables is not annotated correctly.

the mailboxLaunchId is the PK in MailboxBean (class/table)
and joins with EmailAddress via mailboxLaunchId

I have a class
Code:
@Entity
@Name("mailboxBean")
@Table(name = "MAILBOX_LAUNCH")
public class MailboxBean implements Serializable
{
    @Id @GeneratedValue
    @Column(name = "MAILBOX_LAUNCH_ID")
    private Long mailboxLaunchId = null;

    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "MAILBOX_LAUNCH_ID")
    private List <EmailAddress> emailAddresses;
}


so the above class has a collection of these objects
Code:
@Entity
@Name("emailAddress")
@Table(name = "MAILBOX_LAUNCH_EMAIL_ADDRESS")
public class EmailAddress implements Serializable
{
    @Id @GeneratedValue
    @Column(name = "EMAIL_ADDRESS_ID")
    private Long emailAddressId;

    @Column(name = "MAILBOX_LAUNCH_ID")
    private Long mailboxLaunchId;
}


when i call persit(mailboxBean); and that mailboxBean
has some EmailAddress objects in it emailAddresses property, i get

Caused by java.sql.BatchUpdateException with message: "ORA-01400: cannot insert NULL into ("MB_LAUNCH"."MAILBOX_LAUNCH_EMAIL_ADDRESS"."MAILBOX_LAUNCH_ID") "

can tell me what annotation i am missing to get this to work. seems like EmailAddress property mailboxLaunchId (a FK from MailboxLaunch)
is null in my bean, but i was thinking hibernate would take care of this, but i am missing
something to enable this type of batch update.

thanks


Top
 Profile  
 
 Post subject: Re: help w/ simple joining of 2 table with annotations
PostPosted: Fri Jan 08, 2010 12:39 pm 
Newbie

Joined: Thu Jan 07, 2010 6:08 pm
Posts: 2
now that i have thought about this for a day, i don't even think the
@OneToMany(mappedBy="mailboxLaunchId", cascade=CascadeType.ALL)
is correct.

typically, the child class has as a property, the parent class.
that is what I am seeing in all the examples

but for this senerio I have in the child class, a reference to the parent's
primary key, not the parent iteslf, so now i am wondering if
I need the @OneToMany annotation

anyone care to help?


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.