Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] JPA insert failure

Any luck on this? Looks like you're missing the @ManyToOne on the other side:

See: http://en.wikibooks.org/wiki/Java_Persistence/OneToMany

Also consider using Dali to generate your entities. Don't fret too
much, when beginning JPA I was running into mapping issues like this
every day :)

./tch



On Fri, Sep 26, 2008 at 2:03 PM, John Fisher <fisher23@xxxxxxxx> wrote:
>
>
> Hi folks,
>
>
>
> I'm having a problem with EclipseLink, as illustrated in the example below.
> Perhaps someone can tell  me what I'm doing wrong here.
>
>
>
> I've fictionalized the example somewhat, but basically I have two tables,
> Magazine and Subscription, and a one-to-many relationship between them. At
> runtime, I need to be able to load up the current data, and add
> subscriptions for a specific magazine.
>
>
>
> In order to get things to load properly without errors, I need to have
> "insertable=false, updatable=false" for all but one of the SubscriptionPK
> fields. If I don't put that annotation tag in, I get the error, "Multiple
> writable mappings exist for the field [SUBSCRIPTION.NAME]. Only one may be
> defined as writable, all others must be specified read-only."
>
>
>
> Unfortunately, with the "insertable=false, updatable=false" annotation, I
> can't seem to add subscription records to the Magazine. Specifically,
> address and city are showing up as null on the SQL insert statement that
> EclipseLink generates, and the insertion fails. The name field appears fine
> in the SQL statement binding.
>
>
>
> Any idea how to establish a OneToMany relationship where I can add items to
> the "many" table?
>
>
>
> And, no, I don't have any ability to do a join table – the database
> structure is out of my control. L
>
>
>
> Thanks,
>
> John
>
>
>
>
>
>
>
> @Entity
>
> public class Magazine {
>
>
>
>    @EmbeddedId private MagazinePK id;
>
>
>
>    // . . . some other stuff here
>
>
>
>     @OneToMany(cascade= {CascadeType.ALL}, fetch=FetchType.EAGER,
> mappedBy="magazine")
>
>     private Set<Subscription> subscriptions;
>
>
>
> }
>
>
>
>
>
> @Entity
>
> public class Subscription {
>
>
>
>    @EmbeddedId SubscriptionPK id;
>
>
>
>    private Magazine magazine;
>
>
>
>    // . . . some other stuff here
>
>
>
>
>
> }
>
>
>
> @Embeddable
>
> public class SubscriptionPK implements Serializable {
>
>
>
>     private String name;
>
>
>
>     @Column(insertable=false, updatable=false)
>
>     private String address;
>
>
>
>     @Column(insertable=false, updatable=false)
>
>     private String city;
>
>
>
> }
>
>
>
>
>
>
>
>
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>


Back to the top