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.  [ 4 posts ] 
Author Message
 Post subject: Many-to-many mapping issue
PostPosted: Sun Aug 30, 2009 5:23 pm 
Newbie

Joined: Tue Apr 06, 2004 8:44 am
Posts: 9
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?

Code:
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:

Code:
<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:
Code:
...
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'
...


Top
 Profile  
 
 Post subject: Re: Many-to-many mapping issue
PostPosted: Tue Sep 01, 2009 9:29 pm 
Newbie

Joined: Tue Apr 06, 2004 8:44 am
Posts: 9
I had a different field mapped incorrectly. I mapped the column name using the field name accidentally. oops :-)


Top
 Profile  
 
 Post subject: Re: Many-to-many mapping issue
PostPosted: Fri Sep 11, 2009 10:50 am 
Newbie

Joined: Tue Apr 06, 2004 8:44 am
Posts: 9
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.


Top
 Profile  
 
 Post subject: Re: Many-to-many mapping issue
PostPosted: Sat Sep 12, 2009 10:29 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
anything with "get*" or "load*" readOnly


An interesting solution. Let's hope that doesn't cause any problems in the future.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.