-->
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.  [ 2 posts ] 
Author Message
 Post subject: Unknown column in fieldlist (ManyToMany, MapKey)
PostPosted: Tue Sep 19, 2006 8:05 pm 
Newbie

Joined: Wed Aug 03, 2005 1:40 pm
Posts: 1
Hibernate generates an unknown field using the following mapping. Any idea?

hibernate-3.2.0.CR2, hibernate-annotations-3.2.0.CR1
Mysql 5.0.18


Quote:
Tables

Code:
person (int id)
attribute(int id)
person_attribute (int person_id, int attribute_id)



Code:
@Entity
public class Attribute implements java.io.Serializable
{
    private int id;
    private Map<Integer, Person> persons = new HashMap<Integer, Person>(0);
   
    @ManyToMany(mappedBy = "attributes")
    @MapKey(name="id")
    public Map<Integer, Person> getPersons()
    {
        return this.persons;
    }
}



Code:
@Entity
public class Person implements java.io.Serializable
{
    private int id;

    @ManyToMany
    @JoinTable(name="person_attribute",
            joinColumns={@JoinColumn(name="person_id",referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="attribute_id", referencedColumnName="id")})
    @MapKey(name="id")
    public Map<Integer, Attribute> getAttributes()
}




Code:
Attribute attribute = (Attribute) s.load(Attribute.class, 1);
       
Map<Integer, Person> persons = attribute.getPersons();
for (Person person : persons.values()){           
   out.println(person.getId());
}
Person person = (Person) s.load(Person.class, 1);
Map<Integer, Attribute> attributes = person.getAttributes();
for (Attribute attribute1 : attributes.values()){           
   out.println(attribute1.getId());
}





/* load collection bug.Attribute.persons */ select persons0_.attribute_id as attribute2_1_, persons0_.person_id as person1_1_, persons0_.id as formula1_1_, person1_.id as id0_0_ from person_attribute persons0_ left outer join hibernatebug.person person1_ on persons0_.person_id=person1_.id where persons0_.attribute_id=?
[ 0] WARN - ate.util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22
[ 0] ERROR - ate.util.JDBCExceptionReporter - Unknown column 'persons0_.id' in 'field list'



/* load collection bug.Person.attributes */ select attributes0_.person_id as person1_1_, attributes0_.attribute_id as attribute2_1_, attributes0_.id as formula0_1_, attribute1_.id as id1_0_ from person_attribute attributes0_ left outer join hibernatebug.attribute attribute1_ on attributes0_.attribute_id=attribute1_.id where attributes0_.person_id=?
[ 0] WARN - ate.util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22
[ 0] ERROR - ate.util.JDBCExceptionReporter - Unknown column 'attributes0_.id' in 'field list'


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think it is fixed in CR2

_________________
Emmanuel


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