-->
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: Relation: alle Artikel einer Kategorie
PostPosted: Sun Jan 27, 2008 11:33 am 
Newbie

Joined: Sat Jan 26, 2008 7:19 am
Posts: 11
Location: Germany, Huerth
Ich muss sagen, ich bin, auch wenn ich mit Hibernate das erste Mal arbeite, schon ziemlich weit. Nun bin ich jedoch wieder an einen Punkt gekommen, der mich hindert weiterzumachen. Ganz grob gesehen habe ich folgende Tabellen:

Tabelle: article
Code:
id
category_id


Tabelle: category
Code:
id
name


Nun möchte ich eine getter-Methode für alle Artikel einer bestimmten Kategorie. In meiner Category-Klasse sieht es bereits wie folgt aus:

Code:
class Category extends Table
{
    private Set articles = new HashSet();
   
    [...]
   
    public Set getArticles() {
        return articles;
    }
}


Soweit ist es ja noch okay, jedoch weiß ich nicht genau wie meine category.hbm.xml auszusehen hat. Ich habe bereits etwas rumprobiert, aber irgendwie will das nicht.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="de.flabben.table.Category" schema="flabben" table="category">
        <id name="id" column="category_id" type="java.lang.Integer">
            <generator class="sequence">
                <param name="sequence">flabben.category_id_seq</param>
            </generator>
        </id>
        <property name="name" column="category_name" not-null="true" type="java.lang.String" />
        <set name="articles" schema="flabben" table="article">
            <key not-null="true" column="category_id" />
            <one-to-many class="de.flabben.table.Article" />
        </set>
    </class>
</hibernate-mapping>


Wenn ich meinen Code testen will, bekomme ich folgende Fehlermeldung:

Code:
init:
deps-jar:
compile:
run:
16:25:44,137  INFO Environment:514 - Hibernate 3.2.5
16:25:44,153  INFO Environment:532 - loaded properties from resource hibernate.properties: {<hibernate-configuration>=, <session-factory>=, <mapping=resource="de/flabben/table/definition/tag.hbm.xml" />, "-//Hibernate/Hibernate=Configuration DTD 3.0//EN", </session-factory>=, <?xml=version="1.0" encoding="utf-8"?>, hibernate.bytecode.use_reflection_optimizer=false, </hibernate-configuration>=, <!--=mapping files -->, "http=//hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">, <!DOCTYPE=hibernate-configuration PUBLIC, <property=name="hibernate.show_sql">true</property>}
16:25:44,160  INFO Environment:681 - Bytecode provider name : cglib
16:25:44,164  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
16:25:44,280  INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
16:25:44,282  INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
16:25:44,732  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/article.hbm.xml
16:25:44,864  INFO HbmBinder:300 - Mapping class: de.flabben.table.Article -> article
16:25:44,881  INFO HbmBinder:1422 - Mapping collection: de.flabben.table.Article.tags -> article_tag
16:25:44,886  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/article_tag.hbm.xml
16:25:44,927  INFO HbmBinder:300 - Mapping class: de.flabben.table.ArticleTag -> article_tag
16:25:44,930  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/author.hbm.xml
16:25:44,988  INFO HbmBinder:300 - Mapping class: de.flabben.table.Author -> author
16:25:44,991  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/category.hbm.xml
16:25:45,011  INFO HbmBinder:300 - Mapping class: de.flabben.table.Category -> category
16:25:45,013  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/comment.hbm.xml
16:25:45,042  INFO HbmBinder:300 - Mapping class: de.flabben.table.Comment -> comment
16:25:45,045  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/tag.hbm.xml
16:25:45,058  INFO HbmBinder:300 - Mapping class: de.flabben.table.Tag -> tag
16:25:45,059  INFO Configuration:1541 - Configured SessionFactory: null
16:25:45,063 DEBUG InitSessionFactory:118 - classic factory
16:25:45,119  INFO HbmBinder:2385 - Mapping collection: de.flabben.table.Category.articles -> article
%%%% Error Creating HibernateSessionFactory %%%%
org.hibernate.MappingException: Repeated column in mapping for entity: de.flabben.table.Article column: category_id (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.RootClass.validate(RootClass.java:192)
        at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
        at de.flabben.hibernate.InitSessionFactory.initSessionFactory(InitSessionFactory.java:119)
        at de.flabben.hibernate.InitSessionFactory.getInstance(InitSessionFactory.java:60)
        at de.flabben.application.Main.main(Main.java:29)
Exception in thread "main" org.hibernate.HibernateException: Could not initialize the Hibernate configuration
        at de.flabben.hibernate.InitSessionFactory.initSessionFactory(InitSessionFactory.java:127)
        at de.flabben.hibernate.InitSessionFactory.getInstance(InitSessionFactory.java:60)
        at de.flabben.application.Main.main(Main.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)


Kann mir wohl jemand netterweise erklären, was genau da falsch ist. Es kann sein, dass <key not-null="true" column="category_id" /> komplett falsch ist, aber wie gesagt, ich habe einiges ausprobiert, aber nichts wollte so wirklich und ich habe mir auch einige Beispiele ausgeschaut, welche ich bei Google gefunden habe, aber wirklich weitergeholfen haben die mich nicht.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 27, 2008 7:15 pm 
Newbie

Joined: Sat Jan 26, 2008 7:19 am
Posts: 11
Location: Germany, Huerth
Habs auf der Heimfahrt hinbekommen :)


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.