Skip to main content

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

 

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;

 

}

 

 

 

 


Back to the top