facebook

hibernate many-to-many ralationship issue

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #301971 Reply

    dirkdiggler
    Member

    I probably just need a new set of eyes on this. I have an app_user table, an authorization table and an auth_user table. I know that column doesn’t exist…I don’t see how I’m referencing it. Any ideas?

    mysql> desc auth_user;
    | auth_user_id     | bigint(20)  | NO 
    | user_id          | bigint(20)  | NO 
    | auth_id          | bigint(20)  | NO 
    | date_active      | datetime    | NO 
    | date_inactive    | datetime    | YES
    ...
    
    mysql> desc authorization;
    | auth_id          | bigint(20)  | NO 
    | app_id           | bigint(20)  | NO 
    | auth_name        | varchar(10) | NO 
    | description      | varchar(50) | NO 
    ...
    
    mysql> desc app_user;
    | user_id          | bigint(20)  | NO 
    | user_name        | varchar(20) | NO 
    | password         | varchar(20) | NO 
    | active_date      | datetime    | YES
    | inactive_date    | datetime    | YES
    ...

    map:

    <class name="User" table="APP_USER">
        <id name="id" type="java.lang.Long">
            <column name="USER_ID" precision="18" scale="0" />
            <generator class="identity" />
        </id>
        <property name="userName" type="string" column="USER_NAME" />
        <property name="password" type="string" column="PASSWORD" />
        <property name="activeDate" type="timestamp" column="ACTIVE_DATE" />
        <property name="inactiveDate" type="timestamp" column="INACTIVE_DATE" />
        <set name="auths" table="auth_user" inverse="true" lazy="false">
            <key column="USER_ID"/>
            <many-to-many class="com.gtsyn.security.bean.Authorization" column="AUTH_ID" />
        </set>
        ...
    </class>
    <class name="Authorization" table="AUTHORIZATION">
        <id name="id" type="java.lang.Long">
            <column name="AUTH_ID" precision="18" scale="0" />
            <generator class="identity" />
        </id>
        <property name="authName" type="string" column="AUTH_NAME" />
        <property name="description" type="string" column="DESCRIPTION" />
        <many-to-one name="application" column="id" unique="true" not-null="true" />
        <set name="users" table="auth_user" inverse="true" lazy="false">
            <key column="AUTH_ID"/>
            <many-to-many class="com.gtsyn.security.bean.User" column="USER_ID" />
        </set>
        ...
    </class>

    query:
    “from User as model where model.userName = ‘” + user.getUserName() + “‘ and model.password = ‘” + user.getPassword() + “‘”;

    error:

    ...
    Hibernate: 
        /* load collection com.gtsyn.security.bean.User.auths */ select
            auths0_.USER_ID as USER2_1_,
            auths0_.AUTH_ID as AUTH1_1_,
            authorizat1_.AUTH_ID as AUTH1_8_0_,
            authorizat1_.AUTH_NAME as AUTH2_8_0_,
            authorizat1_.DESCRIPTION as DESCRIPT3_8_0_,
            authorizat1_.CREATE_DATE as CREATE4_8_0_,
            authorizat1_.CREATE_USER as CREATE5_8_0_,
            authorizat1_.LAST_UPDATE as LAST6_8_0_,
            authorizat1_.LAST_UPDATE_USER as LAST7_8_0_,
            authorizat1_.id as id8_0_ 
        from
            auth_user auths0_ 
        left outer join
            AUTHORIZATION authorizat1_ 
                on auths0_.AUTH_ID=authorizat1_.AUTH_ID 
        where
            auths0_.USER_ID=?
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'authorizat1_.id' in 'field list'
    ...
    #302013 Reply

    dirkdiggler
    Member

    I had a different field mapped incorrectly. I mapped the column name using the field name accidentally. oops 🙂

    #302349 Reply

    dirkdiggler
    Member

    I discovered that there’s an issue with the way that my transactions are being managed…so as I figured early on, it has to be a spring config issue with the way I’m telling Hibernate to operate. Until I figure that out, I’ve worked around it by actually defining a transaction & making anything with “get*” or “load*” readOnly.

    #302368 Reply

    dirkdiggler,
    Good to know that you are all set.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: hibernate many-to-many ralationship issue

You must be logged in to post in the forum log in