-->
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.  [ 6 posts ] 
Author Message
 Post subject: Unknown column 'gamechess0_.playerBlack' in 'field list'
PostPosted: Wed Mar 15, 2006 3:36 pm 
Newbie

Joined: Wed Mar 15, 2006 3:20 pm
Posts: 7
Hi,
I hope you can help, I really don't understand why I'm getting the following error
Code:
0    [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Unknown column 'gamechess0_.playerBlack' in 'field list'


Hibernate version: 3.1 MySQL Version: 4.1.10a

My User object Mapping:

Code:
<class name="db.objects.User" table="user">
        <id name="username" column="username" />
       
        <property name="password" column="password" />
        <property name="firstName" column="first_name" />
        <property name="lastName" column="last_name" />
        <property name="email" column="email" />
        <property name="countryId" column="country" />
        <property name="gender" column="gender" type="boolean" />
        <property name="rating" column="rating" />
       
        <set name="roles" table="user_role">
           <key column="username" />
           <element type="string" column="role" />
        </set>
        <many-to-one name="country" foreign-key="countryId" insert="false" update="false" />
    </class>


My GameChess object Mapping:
Code:
    <class name="db.objects.GameChess" table="game_chess">
        <id name="id" column="id">
            <generator class="native"/>
        </id>
       
        <property name="title" column="title" />
        <property name="playerWhiteId" column="player_white" />
        <property name="playerBlackId" column="player_black" />
        <property name="timeLimit" column="time_limit" />
        <property name="board" column="board" />
        <property name="ratingMin" column="rating_min" />
        <property name="ratingMax" column="rating_max" />
       
        <many-to-one name="playerBlack" foreign-key="playerBlackId" insert="false" update="false" />
    </class>


The country many-to-one relationship you see above is working perfectly, The playerBlack is of type User as expected...But the many-to-one relationship in the GameChess object gives me the error.

help!

thanks a lot
Eurig


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 5:36 pm 
Newbie

Joined: Wed Mar 15, 2006 3:20 pm
Posts: 7
I've managed to get around this problem by replacing...
Code:
<many-to-one name="playerBlack" foreign-key="playerBlackId" insert="false" update="false" />

in the GameChess object with...
Code:
<many-to-one name="playerBlack" column="player_black" insert="false" update="false" />

The player_black is the database field which I'm after. But now I'm wondering if the first one is actualy supposed to work? Can I reference the objects foreign-key or am I using it incorrectly?

Regards,
Eurig


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 5:41 pm 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
I see 2 things here that could be the cause:

1. You are using the foreign-key property and setting that to the property name. However, I believe this foreign-key property is only used when you are generating a schema based on hibernate mapping files. That way it knows what to name the constraint.

2. If you are creating a many-to-one relationship to a User, your mapping needs fixed:

Try this as your mapping and see how that works for you. Firstly you need to specify the class the relationship is pointing to. Next you must tell it the column of the foreign key, which looks to be player_black. Thirdly, I'd remove your mapping of the playerBlackId property. You probably won't need it if you are mapping the relationship.

Code:
<many-to-one
            name="playerBlack"
            class="<your fully-qualified User object class>"
            cascade="none"
            outer-join="auto"
            update="false"
            insert="false"
            column="player_black"/>
[/code]

_________________
-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 6:02 pm 
Newbie

Joined: Wed Mar 15, 2006 3:20 pm
Posts: 7
Thanks for your reply Chris...

You have answered a lot! But I have one question for you...

TheXFed wrote:
Code:
<many-to-one
            name="playerBlack"
            class="<your fully-qualified User object class>"
            cascade="none"
            outer-join="auto"
            update="false"
            insert="false"
            column="player_black"/>

I've looked up the outer-join="auto" attribute above and I can't seem to find it anywhere in the 3.1 documentation. What does it do, or could you point me to some text where it tells me...

Much appreciated,
Eurig


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 9:19 am 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
Good question. Actually I generate my mapping files using XDoclet, so it must just add that one in there by default. Looking at the DTD, valid values for that are true, false, and auto. However, I cannot find any information about it in the manual.

_________________
-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 8:13 pm 
Newbie

Joined: Wed Mar 15, 2006 3:20 pm
Posts: 7
I still can't find any info anywhere. But I presume that it uses outer-join queries when querying as opposed to select queries. Alhough i'm not sure what the "auto" does


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