Hello,
Because the Document's Meeting database column is set by the documentPk meeting attribute, it needs to be set prior to a flush or commit. This is controlled through the DocumentPK not through a relationshiop (the relationship is marked as not insertable or updatable), so it needs to be set by the application prior to persist. So you will need to persist Meeting and possibly flush to get its primary key set to use in the Document's Pk value.
If you are not tied to JPA 1.0 behaviour and can try previews of the JPA2.0, EclipseLink allows the meeting1 to be annotated with the @MappedById or even allow it to be marked as the @Id if you want to use a PK class instead of embeddableId in the Entity directly. This will give you the behaviour you are expecting, allowing it to get the target Meeting id to use in Document.
Best Regards,
Chris
----- Original Message -----
From: makcro_at_gmail.com
To: persistence_at_glassfish.dev.java.net
Sent: Sunday, August 9, 2009 8:33:31 AM GMT -05:00 US/Canada Eastern
Subject: Toplink cascade with embedded id and autoincrement
hi,
Im having this problem with my project:
public class Meeting implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
....
with relationship
@OneToMany(cascade = CascadeType.ALL, mappedBy = "meeting1", fetch =
FetchType.LAZY)
private Collection<Document> documentCollection;
and the Document entity:
public class Document implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected DocumentPK documentPK;
....
@JoinColumn(name = "Meeting", referencedColumnName = "ID", insertable =
false, updatable = false)
@ManyToOne(optional = false, cascade=CascadeType.ALL)
private Meeting meeting1;
and documentPK
@Embeddable
public class DocumentPK implements Serializable {
@Basic(optional = false)
@Column(name = "ID")
private Integer id;
@Basic(optional = false, fetch=FetchType.EAGER)
@Column(name = "Meeting", nullable=false)
private Integer meeting;
problem is when i create a meeting and add some documents to it I get the
exception:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs
(12/23/2008))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Column 'Meeting' cannot be null
Error Code: 1048
Call: INSERT INTO DOCUMENT (Name, Note, File, FileName, ID, Meeting) VALUES
(?, ?, ?, ?, ?, ?)
bind => [null, null, [B_at_fbb498, j2ee_books.part2.rar, null, null]
Query:
InsertObjectQuery(org.ipo.mm.ejb.entities.Document[documentPK=org.ipo.mm.ejb.entities.DocumentPK[id=null,
meeting=null]])
usgin glassfish v2, mysql 5.0 on fedora 10
any ideas?
--
View this message in context: http://www.nabble.com/Toplink-cascade-with-embedded-id-and-autoincrement-tp24886752p24886752.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.