-->
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.  [ 1 post ] 
Author Message
 Post subject: Table per class and repeated column
PostPosted: Mon Aug 13, 2007 6:33 pm 
Newbie

Joined: Mon Aug 13, 2007 6:02 pm
Posts: 1
Location: Rio de Janeiro, Brazil
Hi friends.

I'm quite new to JPA/Hibernate so it may be a noobish question, although I couldn't find the answer at this forum nor Google or any other information source.

My problem lays over a legacy database which I am not allowed to alter.

Here is it:

I have hierarchies which are clearly mapped as "table per class" strategy. Each class has it's own table with all it's attributes in it, even those that are inherited. Except one.
The problem is exactly with this "except one".
This attribute exists only in the table of the top level class of each hierarchy.

I tried to map as transient on subclasses and at the same time as an attribute of a "secondary table", pointing to the table at the root of the hierarchy. It says that the column is repeated. :¬(
I even tried to map it as transient only (without using the secondary table trick) but I got the same error.

I have already read all the reference documentation and I could not find the answer for this problem.

I hope any of you can help me.

Hibernate version:
19:21:14,484 INFO Version:15 - Hibernate Annotations 3.3.0.GA
19:21:14,515 INFO Environment:514 - Hibernate 3.2.4.sp1
19:21:14,625 INFO Version:15 - Hibernate EntityManager 3.3.1.GA

Full stack trace of any exception that occurs:
javax.persistence.PersistenceException: org.hibernate.MappingException: Repeated column in mapping for entity: br.ufrj.cos.lens.taba.modelo.FerramentaSoftware column: OID (should be mapped with insert="false" update="false")
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at br.ufrj.cos.lens.taba.testes.TabaTesteEntityManager.<init>(TabaTesteEntityManager.java:35)
at br.ufrj.cos.lens.taba.testes.TesteTaba.startupJPA(TesteTaba.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: br.ufrj.cos.lens.taba.modelo.FerramentaSoftware column: OID (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450)
at org.hibernate.mapping.UnionSubclass.validate(UnionSubclass.java:40)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
... 18 more

Name and version of the database you are using: Oracle 10g Express

Debug level Hibernate log excerpt:
No error presented.


Here follows a bit of code:

Code:
@MappedSuperclass
@Entity
public abstract class Modelo {

   /**
    * OID do objeto.
    */
   protected String oid;

   /**
    * Retorna o OID do objeto.
    * @return OID do objeto.
    */
   @Column(name = "OID", unique = false, nullable = true, insertable = true, updatable = true)
   public String getOid(){
      return oid;
   }

   /**
    * Altera o OID do objeto.
    * @param oid OID novo do objeto.
    */
   protected void setOid(String oid) {
      this.oid = oid;
   }

}


@Entity
@Table(name = "TB_ARTEFATO")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Artefato extends Modelo {

   /**
    * Retorna o OID do objeto.
    * @return OID do objeto.
    */
   @Column(name = "OID")
   @Override
   public String getOid() {
      return oid;
   }
}


@Entity
@Table(name = "TB_FERRAMENTASOFTWARE")
@PrimaryKeyJoinColumn(name = "ID")
//@SecondaryTables({@SecondaryTable(name = "Artefato", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")})})
public abstract class FerramentaSoftware extends Artefato {

   /**
    * Retorna o OID do objeto.
    * @return OID do objeto.
    */
   @Override
//   @JoinColumn(table = "Artefato", name="OID", insertable=false, updatable=false)
   @Transient
   @Column(insertable=false, updatable=false)
   public abstract String getOid();// {
//      return oid;
//   }

}

_________________
Peter P. Lupo
http://pplupo.googlepages.com


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

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.