my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3 OneToMany with Composite Key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3 OneToMany with Composite Key" Watch "EJB 3 OneToMany with Composite Key" New topic

EJB 3 OneToMany with Composite Key

Dean Pullen
Ranch Hand

Joined: May 30, 2003
Posts: 58
Hi all,

Having a problem setting up my first EJB 3 OneToMany relationship with a composite key.

Here's the error:
14:09:01,812 WARN [JDBCExceptionReporter] SQL Error: 957, SQLState: 42000
14:09:01,812 ERROR [JDBCExceptionReporter] ORA-00957: duplicate column name

The 'One' Entity:

The 'Many' Entity:

The Composite Key:

As you can see, I'm trying to map the CommsMessage to multiple CommsRecipients using the 'messageid' value found in both tables.

Any help greatly appreciated.
[ July 04, 2007: Message edited by: Dean Pullen ]
Mike Keith
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
Hi Dean,

You need to make one of your messageId mappings read-only in the CommsMessageRecipient class. We talk about this problem in Chapter 8 of our book, but essentially depending upon the vendor you should make either the ManyToOne mapping to or the @Id mapping as insertable=false, updatable=false.

BTW, in future I think you are supposed to post JPA questions in the O/R forum. Thanks.

Pro JPA 2: Mastering the Java Persistence API
subject: EJB 3 OneToMany with Composite Key
Similar Threads
Cannot be cast to
JPA Multiple Foreign Key Join
One to many mapping problem
Multiple Column Join
ManyToMany relationship with extra field in the joinTable