aspose file tools*
The moose likes Object Relational Mapping and the fly likes ManyToOne relation with composite keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ManyToOne relation with composite keys" Watch "ManyToOne relation with composite keys" New topic
Author

ManyToOne relation with composite keys

Kulbhushan Sharma
Greenhorn

Joined: Oct 15, 2008
Posts: 2
Hello,

I am having problems with JPA using Toplink. I have used the default generated code for entities with NetBeans 6.1.

There are three tables defined in MySQL as




The entities generated lead rightly to Composite Keys with @Embedded and EmbeddedID annotations for the tables FilesOnServer and FolderDetails with additional entities FilesOnServerPK FolderDetailsPK .

I persist the relationship (between the FilesOnServer and FolderDetails entities with the code below



The FileOnServer entity is persisted without error but the PARENT_ID field remains null when I was expecting it to be updated with the FOLDER_ID field from the FolderDetails Table/entity.


In the log the following sql command appears
INSERT INTO files_on_server (FILENAME, FILESIZE, FILE_ID, AUTO_UID) VALUES (?, ?, ?, ?)
bind => [n0n0n.txt, 51, 1001, 1]


The thing I noted it that there is no refernce to the PARENT_ID column here...


Any ideas what I may be doing wrong?

Thanks
Kulbhushan Sharma
Greenhorn

Joined: Oct 15, 2008
Posts: 2
No response.

The workaround we use is to expand the primary key for FilesOnServer to also include the ParentID which works but is a hack.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ManyToOne relation with composite keys
 
Similar Threads
HQL query required with left outer join
simple problem Convert latin1 to UTF-8 in MySQL
simple problem Convert latin1 to UTF-8 in MySQL
simple problem Convert latin1 to UTF-8 in MySQL
autogenerating db-schema cascade=CascadeType.REMOVE but no ON DELETE CASCADE