Hibernate version: hibernate-3.2.0.ga
Hello Everyone,
I'm a newbie to the whole Hibernate & Persistence concepts. So, please forgive me if it's a lousy question. I am trying to find a solution to our dillema that I've encountered in my project.
Basically, there's a following situation. I have a self-contained
Project1 in NetBeans implementing Hibernate & Persistence on
Schema1. Everything in it works perfectly fine.
Then there's another separate
Project2 whose
Schema2 has a cross-schema foreign key referencing a column in
Schema1. I am trying to implement unidirectional
ManyToOne mapping from
Project2 to
Project1. To accomplish that, I've imported
Project1 into
Project2 and tried to put appropriate annotations.
Project1
Code:
package com.database.annotation.db;
...
@Entity
@Table(schema = "eht_annotation_0v1", name = "lt_organism")
...
public class Organism implements Serializable {
@Id
@Column(name = "taxon", nullable = false)
private Integer taxon;
...
}
Project2Code:
package com.database.alignment.db;
import com.database.annotation.db.Organism;
...
@Entity
@Table(schema = "eht_spliceevent_0v1", name = "lt_genome")
...
public class Genome implements Serializable {
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Id
@Column(name = "idgenome", nullable = false)
private Integer genomeId;
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, targetEntity=com.database.annotation.db.Organism.class)
@JoinColumn(name = "taxon", nullable = false)
private Organism organism;
...
public Organism getOrganism() {
return this.organism;
}
public void setOrganism(Organism organism) {
this.organism = organism;
}
}
When I try to instantiate
EntityManagerFactory for
Project2 it bombs with the following exception:
Code:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.database.alignment.db.Genome.organism references an unknown entity: com.database.annotation.db.Organism
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:247)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at SethSpliceTestingGround.main(SethSpliceTestingGround.java:32)
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.database.alignment.db.Genome.organism references an unknown entity: com.database.annotation.db.Organism
at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:56)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:178)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:235)
My suspicion is that I just plainly don't know how to handle persistence across multiple projects. I tried putting the imported class from
Project1 into persistence.xml file of
Project2 between the <class> </class> tags but that had no effect. I guess my question is how do I approach the whole problem of cross-project persistence? Is there a more elegant way besides just copying all the classes from
Project1 to
Project2 and appending a persistence.xml of
Project2 ??? I appreciate your input.