-->
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.  [ 12 posts ] 
Author Message
 Post subject: annotations error: Repeated column in mapping for entity.
PostPosted: Mon May 09, 2005 5:19 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Hibernate version:3.0.2

Mapping documents:
Code:
@Entity
@Table(name="pc_author")
@BatchSize(size=20)

@Lucene(category = "author",
   contentsField = "AuthorContents",
   identifier = @IdentifierField(
      classId = "id",
      luceneId = "AuthorId"))
public class Author implements Identifiable<Long> {

   public static final long serialVersionUID = 1L;

   private Long id;

   @LuceneField(isContent=true, name="AuthorName")
   private String name;

   @LuceneField(isContent=true, name="AuthorEmail", type=LuceneFieldTypes.KEYWORD)
   private String email;

   @LuceneField(name="AuthorInstitution")
   private String institution;

   @LuceneField(name="AuthorTutor")
   private String tutor;

   private Set<Document> documents;


   @Id(generate=GeneratorType.AUTO)
   public Long getId() {

      return this.id;

   }

   @Column(name="author_name")
   public String getName() {

      return this.name;

   }

   @Column(name="author_email")
   public String getEmail() {

      return this.email;

   }

   @Column(name="author_institution")
   public String getInstitution() {

      return this.institution;

   }

   @Column(name="author_tutor")
   public String getTutor() {

      return this.tutor;

   }

   @OneToMany(fetch=FetchType.LAZY, mappedBy="author")
   public Set<Document> getDocuments() {

      return this.documents;

   }

   // setters and other simple methods

}

And the Document mapping for relationship is:
Code:
@ManyToOne
@JoinColumn(name="fk_author_id")
public Author getAuthor() {

   return this.author;

}


Code between sessionFactory.openSession() and session.close():
Code:
AnnotationConfiguration configuration = new AnnotationConfiguration();
configuration.configure(new File("src/config/hibernate.cfg.xml"));

SessionFactory factory = configuration.buildSessionFactory();


Full stack trace of any exception that occurs:
Code:
[INFO ][2005-05-09:09:55:38]= (Environment.java:464) - Hibernate 3.0.2
[INFO ][2005-05-09:09:55:38]= (Environment.java:477) - hibernate.properties not found
[INFO ][2005-05-09:09:55:38]= (Environment.java:510) - using CGLIB reflection optimizer
[INFO ][2005-05-09:09:55:38]= (Environment.java:540) - using JDK 1.4 java.sql.Timestamp handling
[INFO ][2005-05-09:09:55:38]= (Configuration.java:1160) - configuring from resource: hibernate.cfg.xml
[INFO ][2005-05-09:09:55:38]= (Configuration.java:1131) - Configuration resource: hibernate.cfg.xml
[INFO ][2005-05-09:09:55:38]= (AnnotationConfiguration.java:92) - Mapping class using metadata: br.ufpe.liber.pc.model.Author
[INFO ][2005-05-09:09:55:39]= (AnnotationConfiguration.java:92) - Mapping class using metadata: br.ufpe.liber.pc.model.Book
[INFO ][2005-05-09:09:55:39]= (AnnotationConfiguration.java:92) - Mapping class using metadata: br.ufpe.liber.pc.model.Comment
[INFO ][2005-05-09:09:55:39]= (AnnotationConfiguration.java:92) - Mapping class using metadata: br.ufpe.liber.pc.model.Document
[INFO ][2005-05-09:09:55:39]= (AnnotationConfiguration.java:92) - Mapping class using metadata: br.ufpe.liber.pc.model.Page
[INFO ][2005-05-09:09:55:39]= (AnnotationConfiguration.java:92) - Mapping class using metadata: br.ufpe.liber.pc.model.Year
[INFO ][2005-05-09:09:55:39]= (Configuration.java:1272) - Configured SessionFactory: foo
[INFO ][2005-05-09:09:55:39]= (Configuration.java:852) - processing extends queue
[INFO ][2005-05-09:09:55:39]= (Configuration.java:856) - processing collection mappings
[INFO ][2005-05-09:09:55:40]= (AnnotationBinder.java:1471) - Mapping collection: br.ufpe.liber.pc.model.Author.documents -> pc_document
[INFO ][2005-05-09:09:55:40]= (AnnotationBinder.java:1471) - Mapping collection: br.ufpe.liber.pc.model.Page.comments -> pc_comment
[INFO ][2005-05-09:09:55:40]= (Configuration.java:865) - processing association property references
[INFO ][2005-05-09:09:55:40]= (Configuration.java:894) - processing foreign key constraints
Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: br.ufpe.liber.pc.model.Author column: id (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:504)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:526)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:544)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:335)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:188)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:816)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1050)
   at br.ufpe.liber.pc.index.Indexing.main(Indexing.java:417)


Name and version of the database you are using: Mysql Ver 12.22 Distrib 4.0.24, for Win32 (ia32)

Driver JDBC: MySQL Connector/J 3.1.7

Annotations Version: 3.0 beta1

Hello, I am studing hibernate annotations and so I catch the stack when loading an AnnotationConfiguration. I really can't undestand why this is happing because, as you can see, there is no a repeated column in mapping. Someone has any idea about it? Futhermore, seems that this problem occur only when I use one-to-many relationships. Moreover, surprisingly all works fine when I use a custom SchemaExportTask class where I change only the method getConfiguration to:
Code:
private Configuration getConfiguration() throws Exception {

   AnnotationConfiguration cfg = new AnnotationConfiguration();

   if (namingStrategy != null) {
      NamingStrategy ns = (NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance();
      cfg.setNamingStrategy(ns);
   }

   if (configurationFile != null)   cfg.configure(new File(configurationFile));

   String[] files = getFiles();
   for (int i = 0; i < files.length; i++) {
      String filename = files[i];
      if (filename.endsWith(".jar")) {
         cfg.addJar(new File(filename));
      } else if (filename.endsWith(".hbm.xml")) {
         cfg.addFile(filename);
      } else {
         cfg.addAnnotatedClass(ReflectHelper.classForName(filename));
      }
   }

   return cfg;
}

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 12:57 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Hello, I solve this problem. FYI, I rewrite annotations at field level and also change @Entity to @Entity(access=AccessType.FIELD). Futher more, I remove serialVersionUID. I believe that there is some error in reflection inspect for classes/superclasses. Maybe my interface Identifiable was inspect and, this seems not be right. The new mapping is:
Code:
@Entity(access=AccessType.FIELD)
@Table(name="pc_author")

@LuceneAnnotation( category = "author", contentsField = "AuthorContents",
   identifier = @IdentifierField( classId = "id", luceneId = "AuthorId" ) )
public class Author implements Identifiable<Long> {

   @Id(generate=GeneratorType.AUTO)
   private Long id;

   @Column(name="author_name")
   @LuceneTypedField(isContent=true, name="AuthorName")
   private String name;

   @Column(name="author_email")
   @LuceneTypedField(isContent=true, name="AuthorEmail", type=LuceneType.KEYWORD)
   private String email;

   @Column(name="author_institution")
   @LuceneTypedField(name="AuthorInstitution")
   private String institution;

   @Column(name="author_tutor")
   @LuceneTypedField(name="AuthorTutor")
   private String tutor;

   @OneToMany(targetEntity="br.ufpe.liber.pc.model.Document",
      fetch=FetchType.LAZY, mappedBy="author")
   private Set<Document> documents;

   // simple gets, sets and other methods

}

Best regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 4:17 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I do not map the static proerties/field anymore in the CVS version

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 4:46 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
emmanuel wrote:
I do not map the static proerties/field anymore in the CVS version

When you do class hierarchy, do you process interfaces or only superclasses?

valeuz...

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 4:56 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Marcos Silva Pereira wrote:
When you do class hierarchy, do you process interfaces or only superclasses?

Or better, when you process a class hierarchy, do you process interfaces or only superclasses?

ps.: Why there is no a edit button?

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2005 10:11 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
When I check properties of the supeclasses of an entity I only use... superclasses.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 2:40 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
emmanuel wrote:
When I check properties of the supeclasses of an entity I only use... superclasses.

I debug some code and discovery whats happen. If I have classes/interfaces like below:
Code:
public interface Identifiable<ID extends Serializable> {
   ID getId();
}

Code:
@Entity(access=AccessType.PROPERTY)
public class Bah implements Identifiable<Long> {

   private Long id;

   @Id(generate=GeneratorType.AUTO)
   public Long getId() {

      return id;
   }
}

When invoking getDeclaredMethods methods, two getId methods will be assigned in result array. So when I execute the following code:
Code:
Class c = Bah.class;
Method[] methods = c.getDeclaredMethods();
for (Method method : methods) {
   System.out.println(method);
}

Will print:
Code:
public volatile java.io.Serializable Bah.getId()
public java.lang.Long Bah.getId()

This is a problem because AnnotationBinder uses exactly this approach to process classes which are annotated using @Entity(access=AccessType.PROPERTY). I get errors points out there are duplicated columns for id property in classes such like Bah. Maybe AnnotationBinder must uses PropertyDescriptors/BeanInfo instead getDeclaredMethods. This is better because so you will deals with accessor methods only. What you think about it?

valeuz...

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 11:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Are you using the beta2 version? Can you try on it and tell me. I do think it's solved.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 7:38 pm 
Newbie

Joined: Sun Jun 05, 2005 6:17 pm
Posts: 1
Location: Glasgow, Scotland
Hi,

I'm having a similar problem which is probably related. I'm using beta-2 with hibernate 3.0.5 on OS X. I have the following test classes

Code:
public abstract class Parent {
    public abstract Integer getId();
}

@Entity
public class Child extends Parent {
    private Integer id;
    private String name;

    @Id(generate = GeneratorType.AUTO)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}



and a JUnit test which has tries to persist an instance of Child:

Code:
    public void testStuff()
    {
        Session s = sessionFactory.openSession();
        Transaction tx = s.beginTransaction();

        Child c = new Child();
        c.setName("child1");
        s.persist(c);
        tx.commit();
        s.close();
    }


It fails with the same error:

Code:
org.hibernate.MappingException: Repeated column in mapping for entity: Child column: id (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:504)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:526)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:544)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:335)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:188)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:839)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1000)
   at AnnotateTest.setUp(AnnotateTest.java:18)
   at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)


but works OK if I comment out the parent getId() method. I've tracked things through in a debugger and it does seem that the "id" property is being added from the parent class too. Looking at the "execute" method of AnnotedElementInferredData, if it checked for abstract methods thus:

Code:
        if ( method.isSynthetic() ||
                method.isBridge() ||
                Modifier.isStatic( method.getModifiers() ) ||
                Modifier.isAbstract( method.getModifiers() )
           ) {
                  skip = true;
             }


Does this seem sensible?

Luke.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 5:33 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this is not completly related. This one is a known problem and it swill be addressed in the next EJB3 draft.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:28 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Hi, Emmanuel, I do a test and all works fine now (hibernate-3.0.5 and hibernate-annotations-3.0beta2). But, seems that I found other problem. For example, if I have the following class (Identifiable interface like above):
Code:
@Entity( access = AccessType.PROPERTY )
public class Article implements Identifiable<Long> {

    private Long id;

    /**
     * @see br.com.vicinity.hibernate.test.Identifiable#getId()
     */
    @Id( generate = GeneratorType.AUTO )
    @Column( name = "article_id" )
    public Long getId() {

        return id;

    }

    /**
     * @see br.com.vicinity.hibernate.test.Identifiable#setId(java.lang.Long)
     */
    public void setId( Long id ) {

        this.id = id;

    }

    /**
     * A method which the name starts with "get" but is not an accessor
     */
    public String getSomething( int num ) {

        return "The param was " + num;

    }

}

As you can see, the method "getSomething" is not a accessor method, but some other business method. What seems wrong that is all methods which name starts with "get" are processeds as an accessor method. So, when AnnotationConfiguration will build a SessionFactory I get the exception below:
Code:
org.hibernate.PropertyNotFoundException: Could not find a getter for something in class br.com.vicinity.hibernate.test.Article
   at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:213)
   at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:207)
   at org.hibernate.mapping.Property.getGetter(Property.java:240)
   at org.hibernate.tuple.PojoTuplizer.buildPropertyGetter(PojoTuplizer.java:237)
   at org.hibernate.tuple.AbstractTuplizer.<init>(AbstractTuplizer.java:73)
   at org.hibernate.tuple.PojoTuplizer.<init>(PojoTuplizer.java:54)
   at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:47)
   at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:218)
   at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:400)
   at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:104)
   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:211)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
   at br.com.vicinity.test.hibernate.GenericsInterfaceTest.testBuildSessionFactory(GenericsInterfaceTest.java:29)
   at ...

Maybe you should test if method receive a argument.

valeuz...

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 5:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Done thanks

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.