[jboss-user] [EJB 3.0] - Foreign Key fields not set for child entity
lafr
do-not-reply at jboss.com
Wed Sep 12 17:02:43 EDT 2007
My parent Entity looks like this:
public class MbiMsghd implements java.io.Serializable
| {
| /** Field msghdSerial. */
| @Id
| @GeneratedValue(strategy=GenerationType.IDENTITY)
| @Column(name="msghd_serial")
| private java.lang.Integer msghdSerial;
| /** Relation with MbiMsgpa. */
| @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="msghdSerial")
| @OrderBy("msghdSerial,partNo")
| private java.util.Collection<MbiMsgpa> mbiMsgpa = new java.util.ArrayList<MbiMsgpa>();
|
My child entity like this:
@Entity
| @IdClass(value=MbiMsgpa.PK.class)
| @Table(name="mbi_msgpa")
| public class MbiMsgpa implements java.io.Serializable
| {
| /** Field msghdSerial. */
| @Id
| @ManyToOne
| @Column(name="msghd_serial")
| private java.lang.Integer msghdSerial;
|
| /** Field partNo. */
| @Id
| @Column(name="part_no")
| private java.lang.Integer partNo;
|
So the child has a composite primary key and one part of this PK is a FK to the parent.
In my session bean I can create the parent successfully, but the created and added child did not get set the PK/FK fields.
MbiMsgpa mbiMsgpa = new MbiMsgpa();
| mbiMsghd.getMbiMsgpa().add( mbiMsgpa );
| // set all attributes of child entity
| this.entityManager.persist( mbiMsgpa );
|
The key values of the child entity are null when they are inserted into the database.
>From all examples I saw in my book and on the Web I expected the EJB3 container to set the key fields of the child entity.
It does not make any difference if I set up the OneToMany relation uni- or bidirectional.
Did anyone of you get something like this running on JBoss 4.2.2.GA?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4083668#4083668
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4083668
More information about the jboss-user
mailing list