0

How can I use a named sql query in a many to one mapping, using hibernate?

<many-to-one name="accountSetting" class="maxAccountSetting">
        <column name="AC_ACCOUNT" sql-type="VARCHAR2" length="10"/>
</many-to-one>
<sql-query name="maxAccountSetting">
    <return alias="accountSetting" class="interfaces.model.AccountSetting"/>
        SELECT ...
</sql-query>

If this is not possible, is there a way to define a class based on a already created class, like in a named query?

<class>
    <id name="interfaces.model.AccountSetting"/>
    <subselect>
        SELECT ...
    </subselect>
</class>

The goal is to use another table as a many-to-one mapping in the current hibernate definition, but I can't use the "raw" table because it has duplicates in the key i'm using to join the both. The purpose is to incorporate the "fff" column, by joining by AC_ACCOUNT with "eee" being the max value.

This is the table structure:

BALANCE {
    AC_ACCOUNT PK
    aaa PK
    bbb PK
    ccc
    ddd
}
ACCOUNT_SETTING {
    AC_ACCOUNT PK
    eee PK
    fff
    ggg
}
nfvp
  • 1,146
  • 1
  • 8
  • 6

0 Answers0