File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Problem with @ManyToOne on a CompositeId Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem with @ManyToOne on a CompositeId " Watch "Problem with @ManyToOne on a CompositeId " New topic

Problem with @ManyToOne on a CompositeId

Sergio Silva

Joined: May 03, 2006
Posts: 5
I have a Database that i need to persist and that i can't change his structure.

With reverse engineering i created the persistence model, but now i'm with problems:

Class EventActions:

The Pk Class:

The OperationInterval class:

When i validate the model, it gives the error:

org.hibernate.AnnotationException: Column name operationintervalid of Eventactions not found in JoinColumns.referencedColumnName

Caused by: org.hibernate.AnnotationException: Column name operationintervalid of
ions not found in JoinColumns.referencedColumnName
at org.hibernate.cfg.annotations.TableBinder.bindFk(
at org.hibernate.cfg.FkSecondPass.doSecondPass(
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(
at org.hibernate.cfg.Configuration.buildMappings(
at org.hibernate.ejb.Ejb3Configuration.buildMappings(
at org.hibernate.ejb.EventListenerConfigurator.configure(
at org.hibernate.ejb.Ejb3Configuration.configure(
at org.hibernate.ejb.Ejb3Configuration.configure(
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(
at org.ow2.easybeans.persistence.JPersistenceContext.init(
at org.ow2.easybeans.persistence.JPersistenceContext.<init>(
at org.ow2.easybeans.persistence.PersistenceUnitManager.addExtraPersistenceUnitInfos(
at org.ow2.easybeans.persistence.PersistenceUnitManager.<init>(
at org.ow2.easybeans.persistence.xml.PersistenceXmlFileAnalyzer.analyzePersistenceXmlFile(
at org.ow2.easybeans.container.JContainer3.start(
at org.ow2.easybeans.osgi.ejbjar.Activator.startContainer(
at org.ow2.easybeans.osgi.ejbjar.Activator.start(
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$
at Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(
... 14 more
Nested Exception:

So... I commented the joincolumn anotation... and the result is:

org.hibernate.HibernateException: Missing column: operationintervalsByOperationintervalid_operationIntervalId in yogurt.dbx.EventActions

How can i solve this problem ? I can't change the database.
[ October 13, 2007: Message edited by: Sergio Silva ]
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hi Sergio,

In Operationinterval the mappedBy property in @OneToMany annotation should be an attribute in class A that references back to class Operationinterval.

so @OneToMany should be changed to...

public Collection<A> getAByOperationalintervalid() {
return asByOperationintervalid;

At the same time please make sure that the case of columns are the same as declared in your class files. You do require the @JoinColumn.

If there are still some issues, it would be helpful if you paste the entire source code here.

Shailesh Kini.
Sergio Silva

Joined: May 03, 2006
Posts: 5
Yes, i have the code as you tell me to, but have the same problem...

I don't have the rest of the code now, just later, can you guys remember what could be wrong until i post all code?

Sergio Silva

Joined: May 03, 2006
Posts: 5
The code from the original post is updated!

It's all code there now!

Can you guys help me?
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hello Sergio,

I am trying a sample on my end and will post my findings. In the meantime if you have a solution please post it here, it might help other ranchers.
[ October 17, 2007: Message edited by: Shailesh Kini ]
I agree. Here's the link:
subject: Problem with @ManyToOne on a CompositeId
It's not a secret anymore!