Advertisement

02.22.2007 at 12:24PM PST, ID: 22407458
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Using 2 Classes that represent the same database table with EJB3

Asked by ethnarch in Enterprise Java Beans (EJB), Java Programming Language, J2EE

Tags: , , ,

i have 2 classes that both refer to the same table in 2 seperate parts of my application.  Another words say i have a table

parenttable
   ID
   Name
   Date

In each section of my app i only need 1 of the 2 child tables that refer to sometable's id with a foreignkey.  Instead of mapping both of child classes to the parent class, I only mapped one.  Then in the other section of my app i created another parentclass with is only mapped the the second child class.

I keep getting an error that duplicate imports exist:
(BELOW COLLECTION IS THE PARENT CLASS)

Caused by: javax.persistence.PersistenceException: org.hibernate.AnnotationException: Use of the same entity name twice: Collection
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:252)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at collectionEntry.Collection.<clinit>(Collection.java:46)
        ... 23 more
Caused by: org.hibernate.AnnotationException: Use of the same entity name twice: Collection
        at org.hibernate.cfg.annotations.EntityBinder.bindEntity(EntityBinder.java:259)
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:532)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)
        ... 27 more
Caused by: org.hibernate.DuplicateMappingException: duplicate import: Collection refers to both boothstat_downloader.Collection and collectionEntry.Collection (try using auto-import="false")
        at org.hibernate.cfg.Mappings.addImport(Mappings.java:141)
        at org.hibernate.cfg.annotations.EntityBinder.bindEntity(EntityBinder.java:252)
        ... 36 more

The file i am using that describes the persistance unit is:
  <persistence-unit name="Booth_StatPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>boothstat_downloader.Collection</class>
    <class>boothstat_downloader.MoneyDisplay</class>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.FirebirdDialect"/>
      <property name="hibernate.connection.url" value="jdbc:firebirdsql:warehouse01/3050:c:\\zee03\\database\\showtechDB.FDB"/>
      <property name="hibernate.connection.driver_class" value="org.firebirdsql.jdbc.FBDriver"/>
      <property name="hibernate.connection.password" value="masterkey"/>
      <property name="hibernate.connection.username" value="sysdba"/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
    </properties>
  </persistence-unit>
  <persistence-unit name="CollectionEntryPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>collectionEntry.Collection</class>
    <class>collectionEntry.CollectionCount</class>
    <properties>
      <property name="hibernate.connection.url" value="jdbc:firebirdsql:warehouse01/3050:c:\\zee03\\database\\showtechDB.FDB"/>
      <property name="hibernate.connection.driver_class" value="org.firebirdsql.jdbc.FBDriver"/>
      <property name="hibernate.connection.password" value="masterkey"/>
      <property name="hibernate.connection.username" value="sysdba"/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
    </properties>
  </persistence-unit>

is there anyway to make this work so that it does not try to load both Collection Classes?Start Free Trial
 
Loading Advertisement...
 
[+][-]02.22.2007 at 12:28PM PST, ID: 18591145

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Enterprise Java Beans (EJB), Java Programming Language, J2EE
Tags: same, name, entity, use
Sign Up Now!
Solution Provided By: mayankeagle
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.22.2007 at 12:42PM PST, ID: 18591292

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.22.2007 at 12:49PM PST, ID: 18591354

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.22.2007 at 01:20PM PST, ID: 18591640

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32