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.7Annotations Version: 3.0 beta1Hello, 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;
}