Hibernate: could not resolve property

ChristianK

Aktives Mitglied
Guten Abend zusammen 🙂

Nach ausführlicher Recherche und gefühlten hunderten von Forenbeiträgen über dieses Thema komme ich dennoch nicht ans Ziel. Es geht um Hibernate mit MySQL und Entities mit Relationen. Es spuckt mir immer den Fehler "could not resolve property: fileversionById" aus.

Ich arbeite mit IntelliJ und habe mir alles vom Hibernate-Plugin generieren lassen. Und ich gebe zu, ich bin neu auf dem Gebiet Hibernate...

Ich habe etwa folgende Mapping (gekürzt):
Code:
    <class name="ch.backuptresor.database.beans.FileEntity" table="file" schema="" catalog="backuptresor">
        <composite-id mapped="true" class="ch.backuptresor.database.beans.FileEntityPK">
            <key-property name="id">
                <column name="id" sql-type="int" length="10" not-null="true"/>
            </key-property>
            <key-property name="directoryId">
                <column name="directoryId" sql-type="int" length="10" not-null="true"/>
            </key-property>
            <key-property name="mimetypeId">
                <column name="mimetypeId" sql-type="int" length="10" not-null="true"/>
            </key-property>
        </composite-id>
        <property name="localPath">
            <column name="localPath" sql-type="varchar" not-null="true"/>
        </property>
        <property name="localRelativePath">
            <column name="localRelativePath" sql-type="varchar" not-null="true"/>
        </property>
        <property name="clientPath">
            <column name="clientPath" sql-type="varchar" not-null="true"/>
        </property>
        <property name="hash">
            <column name="hash" sql-type="varchar" length="32" not-null="true"/>
        </property>
        <property name="lastModify">
            <column name="lastModify" sql-type="datetime" length="19" not-null="true"/>
        </property>
        <property name="createTime">
            <column name="createTime" sql-type="datetime" length="19" not-null="true"/>
        </property>
        <property name="size">
            <column name="size" sql-type="bigint" length="19" not-null="true"/>
        </property>
        <property name="sizeUnencrypted">
            <column name="sizeUnencrypted" sql-type="bigint" length="19" not-null="true"/>
        </property>
        <property name="pointer">
            <column name="pointer" sql-type="varchar"/>
        </property>
        <many-to-one name="mimetypeByMimetypeId" class="ch.backuptresor.database.beans.MimetypeEntity">
            <column name="mimetypeId" not-null="true"/>
        </many-to-one>
        <many-to-one name="fileversionById" class="ch.backuptresor.database.beans.FileversionEntity">
            <column name="id" not-null="true"/>
        </many-to-one>
        <many-to-one name="queueById" class="ch.backuptresor.database.beans.QueueEntity">
            <column name="id" not-null="true"/>
        </many-to-one>
        <set name="directoryById" inverse="true">
            <key>
                <column name="id" not-null="true"/>
            </key>
            <one-to-many not-found="ignore" class="ch.backuptresor.database.beans.DirectoryEntity"/>
        </set>
    </class>
    <class name="ch.backuptresor.database.beans.FileversionEntity" table="fileversion" schema=""
           catalog="backuptresor">
        <composite-id mapped="true" class="ch.backuptresor.database.beans.FileversionEntityPK">
            <key-property name="id">
                <column name="id" sql-type="int" length="10" not-null="true"/>
            </key-property>
            <key-property name="fileId">
                <column name="fileId" sql-type="int" length="10" not-null="true"/>
            </key-property>
            <key-property name="commitId">
                <column name="commitId" sql-type="int" length="10" not-null="true"/>
            </key-property>
        </composite-id>
        <property name="size">
            <column name="size" sql-type="bigint" length="19" not-null="true"/>
        </property>
        <property name="sizeUnencrypted">
            <column name="sizeUnencrypted" sql-type="bigint" length="19" not-null="true"/>
        </property>
        <set name="fileById" inverse="true">
            <key>
                <column name="id" not-null="true"/>
            </key>
            <one-to-many not-found="ignore" class="ch.backuptresor.database.beans.FileEntity"/>
        </set>
        <set name="commitById" inverse="true">
            <key>
                <column name="id" not-null="true"/>
            </key>
            <one-to-many not-found="ignore" class="ch.backuptresor.database.beans.CommitEntity"/>
        </set>
    </class>

Demnach müsste ein Query zum alle Einträge der Tabelle "fileversion" der zugehörigen Zeile aus "file" doch etwa so lauten:
Code:
from FileEntity f inner join f.fileversionById where f.id = 1
Der Fehler ist, wie oben genannt:
Code:
[2014-01-06 21:51:06] java.lang.RuntimeException: org.hibernate.QueryException: could not resolve property: fileversionById of: org.example.database.beans.FileEntity [from org.example.database.beans.FileEntity

Das MySQL-äquivalent wäre dazu ja
Code:
 SELECT * FROM `file` as f INNER JOIN `fileversion` as fv ON (f.id = fv.fileId)

Was mache bzw. verstehe ich da falsch?
 

Zurück
Oben