Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem defining insertable=false at column in a embedded class

dnlcy-JavaNetMay 1 2007 — edited May 2 2007
Hi
I have an embedded class (ClassPK) to define the primary key for my entity bean (ClassBean). But one of his fields is a foreign key for another entity bean (AnotherBean) and so this field must be populated by the relationship that exist in the entity (ClassBean) with the annotation @joincolumn.

I think the idea is correct. Although I have a problem with the population of this field. Because both the association and the field it self tries to write in DB. The solution would be to add in the @column annotation the argument insertable=false. So that just the association tries to populate the field.

But this seems not to work. the "Multiple writable mappings exist for the field" exception is thrown.

If I try to put the insertable=false at the association instead of the field. A null value is populated.

This is the code:

@Entity
@Table(name="AnotherBeanTable")
public class AnotherBean implements Serializable{

@Id
@Column(name = "FIELD_NB", nullable=false)
protected BigInteger fieldNb;

/*
getters and setters and others methods
*/
}


@Entity
@Table(name="ClassBeanTable")
public class ClassBean implements Serializable{
/**
* EmbeddedId primary key field
*/
@EmbeddedId
protected ClassPK classPk;

@JoinColumn(name = "FIELD_NB", referencedColumnName = "FIELD_NB")
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.ALL})
private AnotherBean anotherBean;

/*
getters and setters and others methods
*/
}


@Embeddedable
public class ClassPK implements Serializable{

@Column(name = "FIELD_NB", nullable = false,
insertable = false, updatable = false)
protected BigInteger fieldNb;

@Column(name = "TEXT_FIELD", nullable = false)
private String textField;

/*
getters and setters and others methods
*/
}





Is there another way to do this? Or is there any mistakes?

I believe that its possible to do this with IdClass, but I would like to use an embedded class. And I think this should be possible
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 30 2007
Added on May 1 2007
2 comments
1,329 views