-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Implement Persistence across Entities in different projects
PostPosted: Mon Nov 27, 2006 3:58 pm 
Newbie

Joined: Mon Nov 27, 2006 3:01 pm
Posts: 2
Location: Gaithersburg, MD
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;

...

}

Project2
Code:
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 2:45 pm 
Newbie

Joined: Mon Nov 27, 2006 3:01 pm
Posts: 2
Location: Gaithersburg, MD
Figured it out on my own using some of the posts here.

It appears that you have to copy all classes from the imported project's persistence.xml to the one in the current project.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.