views:

32

answers:

2

I m able to get values using JPA when i have only mapped one table

Now when i have gone for mapping related tables i get the error

  Only one may be defined as writable, all others must be specified read-only.
  Mapping: org.eclipse.persistence.mappings.OneToOneMapping[userId1]

I m using [EclipseLink-0] (Eclipse Persistence Services - 2.0.1.v20100213-r6600)

In one of the child tables i have this code

@OneToMany(cascade = CascadeType.ALL, mappedBy = "albumId")
private Collection<Images> imagesCollection;
@JoinColumn(name = "user_id", referencedColumnName = "User_ID")
@ManyToOne(optional = false)
private Roleuser userId;
@JoinColumn(name = "album_image", referencedColumnName = "image_id")
@ManyToOne
private Images albumImage;
@JoinColumn(name = "album_image", referencedColumnName = "image_id")
@ManyToOne
private Images albumImage1;
@JoinColumn(name = "user_id", referencedColumnName = "User_ID")
@ManyToOne(optional = false)
private Roleuser userId1;

What changes i have to do in this code to make the fields read-only?

or are there any better workaround for not making these fields read only?

A: 

You have two ManyToOne relationships using the same foreign key field. This does not make sense, they will be the same object?

@JoinColumn(name = "album_image", referencedColumnName = "image_id")
@ManyToOne
private Images albumImage;
@JoinColumn(name = "album_image", referencedColumnName = "image_id")
@ManyToOne
private Images albumImage1;

You should have two different foreign key fields, i.e. albumImage and albumImage1.

James
went with openJPA with no issues or so do i think... may be bugging around later... well i have one more question... http://stackoverflow.com/questions/3567438/select-from-two-tables-using-jpql
Pradyut Bhattacharya
i dont know much about JPA but the entity classes i generated with netbeans and they are same with openJPA...
Pradyut Bhattacharya
netbeans generated the classes...well why did netbeans generate two references of a single relation...should i file a bug for netbeans...
Pradyut Bhattacharya
to make one of the JoinColumns read-only, set insertable/updateable=false in the annotation. But you mapping still does not make any sense...
James
Also, please log a bug for this issue, that we should probably just log a warning instead of throwing an error.
James
A: 

Well used openJPA with no issues...may be bugging later .. ;-)

Pradyut Bhattacharya
The issue is your mapping, not the JPA provider. And actually, I'm tempted to say that EclipseLink is doing a better job by reporting an error here.
Pascal Thivent
netbeans generated the classes...well why did netbeans generate two references of a single relation...should i file a bug for netbeans...
Pradyut Bhattacharya
nobody's answering my other question... http://stackoverflow.com/questions/3567438/select-from-two-tables-using-jpql
Pradyut Bhattacharya
I don't know, can't say without seeing the tables.
Pascal Thivent